5.8 Conditions
Prev | Chapter 5 Project components | Next

## 5.8 Conditions

Conditions are nested elements of the condition, if and waitfor tasks.

### 5.8.1 `not`

The `<not>` element expects exactly one other condition to be nested into this element, negating the result of the condition. It doesn't have any attributes and accepts all nested elements of the condition task as nested elements as well.

### 5.8.2 `and`

The `<and>` element doesn't have any attributes and accepts an arbitrary number of conditions as nested elements. This condition is true if all of its contained conditions are, conditions will be evaluated in the order they have been specified in the build file.

The `<and>` condition has the same shortcut semantics as the `&&` operator in some programming languages, as soon as one of the nested conditions is false, no other condition will be evaluated.

### 5.8.3 `or`

The `<or>` element doesn't have any attributes and accepts an arbitrary number of conditions as nested elements. This condition is true if at least one of its contained conditions is, conditions will be evaluated in the order they have been specified in the build file.

The `<or>` condition has the same shortcut semantics as the `||` operator in some programming languages, as soon as one of the nested conditions is true, no other condition will be evaluated.

### 5.8.4 `os`

Test whether the current operating system is of a given type.

Table 5.1: OS Attributes

Attribute | Description | Required
--- | --- | ---
`family` | The name of the operating system family to expect. | Yes

Supported values for the family attribute are:

- windows (for all versions of Microsoft Windows)

- mac (for all Apple Macintosh systems)

- unix (for all Unix and Unix-like operating systems)

### 5.8.5 `equals`

Tests whether the two given Strings are identical

Table 5.2: equals Attributes

Attribute | Description | Required
--- | --- | ---
`arg1` | First string to test. | Yes
`arg2` | Second string to test. | Yes
`casesensitive` | Perform a case sensitive comparision. Default is true. | No
`trim` | Trim whitespace from arguments before comparing them. Default is false. | No

### 5.8.6 `version-compare`

Compares two given versions

Table 5.3: version-compare Attributes

Attribute | Description | Required
--- | --- | ---
`version` | The version you want to compare | Yes
`desiredVersion` | The version you want to compare agains | Yes
`operator` | The operator to use for version comparison. Default is `>=`. | No
debug | Turns on debug mode, that echoes the comparion message. Default is false. | No

    <version-compare version="${someproperty}" desiredVersion="1.3" operator="gt" />

This condition internally uses PHP version_compare(). Operators and behavior are the same.

### 5.8.7 `http`

Condition to wait for a HTTP request to succeed.

Attributes are:

- url - the URL of the request.
- errorsBeginAt - number at which errors begin at.

Table 5.4: http Attributes

Attribute | Description | Required
--- | --- | ---
`url` | The URL of the request. | Yes
`errorsBeginAt` | Number at which errors begin at. - Default: 400 | No

    <http url="http://url.to.test" errorsBeginAt="404" />

### 5.8.8 `isset`

Test whether a given property has been set in this project.

Table 5.5: isset Attributes

Attribute | Description | Required
--- | --- | ---
`property` | The name of the property to test. | Yes

### 5.8.9 `contains`

Tests whether a string contains another one.

Table 5.6: contains Attributes

Attribute | Description | Required
--- | --- | ---
`string` | The string to search in. | Yes
`substring` | The string to search for. | Yes
`casesensitive` | Perform a case sensitive comparision. Default is true. | No

### 5.8.10 `istrue`

Tests whether a string evaluates to true.

Table 5.7: istrue Attributes

Attribute | Description | Required
--- | --- | ---
`value` | value to test | Yes

    <istrue value="${someproperty}"/>
    <istrue value="false"/>

### 5.8.11 `isfalse`

Tests whether a string evaluates to not true, the negation of `<istrue>`

Table 5.8: isfalse Attributes

Attribute | Description | Required
--- | --- | ---
`value` | value to test | Yes

    <isfalse value="${someproperty}"/>
    <isfalse value="false"/>

### 5.8.12 `referenceexists`

Tests whether a specified reference exists.

Table 5.9: referenceexists Attributes

Attribute | Description | Required
--- | --- | ---
`ref` | reference to test for | Yes

    <referenceexists ref="${someid}"/>

### 5.8.13 `available`

This condition is identical to the Available task, all attributes and nested elements of that task are supported, the property and value attributes are redundant and will be ignored.

Prev | Up | Next
5.7 Basic Types | Home | Chapter 6 Extending Phing