# IfTask

Extends \ConditionBase

Perform some tasks based on whether a given condition holds true or not.

This task is heavily based on the Condition framework that can be found in Ant 1.4 and later, therefore it cannot be used in conjunction with versions of Ant prior to 1.4.

This task doesn't have any attributes, the condition to test is specified by a nested element - see the documentation of your `<condition>` task (see the online documentation for example) for a complete list of nested elements.

Just like the `<condition>` task, only a single condition can be specified - you combine them using `<and>` or `<or>` conditions.

In addition to the condition, you can specify three different child elements, `<elseif>`, `<then>` and `<else>`. All three subelements are optional. Both `<then>` and `<else>` must not be used more than once inside the if task. Both are containers for Ant tasks, just like Ant's `<parallel>` and `<sequential>` tasks - in fact they are implemented using the same class as Ant's `<sequential>` task.

The `<elseif>` behaves exactly like an `<if>` except that it cannot contain the `<else>` element inside of it. You may specify as may of these as you like, and the order they are specified is the order they are evaluated in. If the condition on the `<if>` is false, then the first `<elseif>` who's conditional evaluates to true will be executed. The `<else>` will be executed only if the `<if>` and all `<elseif>` conditions are false.

Use the following task to define the `<if>` task before you use it the first time:

      <taskdef name="if" classname="net.sf.antcontrib.logic.IfTask" />

### Crude Example

``

<if> <then> </then> <else> </else> </if>

``

<if> </then> <elseif> <then> </then> </elseif> <else> </else> </if>

author | Stefan Bodewig
package | phing.tasks.system

### Methods

## __construct

    __construct( $taskName = 'component')

inherited

### Arguments

#### $taskName

``

## addAvailable

    addAvailable(\AvailableTask $a) : void

inherited

### Arguments

#### $a

`\AvailableTask`

## A nested <else> element - a container of tasks that will be run if the condition doesn't hold true.

    addElse(\SequentialTask $e)

Not required.

throws |

### Arguments

#### $e

`\SequentialTask`

## addElseIf

    addElseIf(\ElseIfTask $ei)

### Arguments

#### $ei

`\ElseIfTask`

## A nested <then> element - a container of tasks that will be run if the condition holds true.

    addThen(\SequentialTask $t)

Not required.

throws |

### Arguments

#### $t

`\SequentialTask`

## countConditions

    countConditions() : integer

inherited

### Response

`integer`

## createAnd

    createAnd() : \AndCondition

inherited

### Response

`\AndCondition`

## createContains

    createContains() : \ContainsCondition

inherited

### Response

`\ContainsCondition`

## createEquals

    createEquals() : \EqualsCondition

inherited

### Response

`\EqualsCondition`

## createFilesMatch

    createFilesMatch()

inherited

## createHasFreeSpace

    createHasFreeSpace()

inherited

## createHttp

    createHttp()

inherited

## createIsFailure

    createIsFailure()

inherited

## createIsFalse

    createIsFalse() : \IsFalseCondition

inherited

### Response

`\IsFalseCondition`

## createIsFileSelected

    createIsFileSelected()

inherited

## createIsPropertyFalse

    createIsPropertyFalse() : \IsPropertyFalseCondition

inherited

### Response

`\IsPropertyFalseCondition`

## createIsPropertyTrue

    createIsPropertyTrue() : \IsPropertyTrueCondition

inherited

### Response

`\IsPropertyTrueCondition`

## createIsSet

    createIsSet() : \IsSetCondition

inherited

### Response

`\IsSetCondition`

## createIsTrue

    createIsTrue() : \IsTrueCondition

inherited

### Response

`\IsTrueCondition`

## createMatches

    createMatches()

inherited

## createNot

    createNot() : \NotCondition

inherited

### Response

`\NotCondition`

## createOr

    createOr() : \OrCondition

inherited

### Response

`\OrCondition`

## createOs

    createOs() : \OsCondition

inherited

### Response

`\OsCondition`

## createPhingVersion

    createPhingVersion()

inherited

## createReferenceExists

    createReferenceExists() : \ReferenceExistsCondition

inherited

### Response

`\ReferenceExistsCondition`

## createSocket

    createSocket()

inherited

## createVersionCompare

    createVersionCompare()

inherited

## createXor

    createXor() : \XorCondition

inherited

### Response

`\XorCondition`

## Creates the object for the child element

    customChildCreator(string $elementName, \Project $project) : \Condition

inherited

throws |

### Arguments

#### $elementName

`string`

the name of the element that has been requested

#### $project

`\Project`

The project the element is in

### Response

`\Condition`

## getConditions

    getConditions() : array<mixed,\Condition>

inherited

### Response

`array<mixed,\Condition>`

## Required for IteratorAggregate

    getIterator()

inherited

## Returns a reference to current project

    getProject() : \Project

inherited

### Response

`\Project`

Reference to current porject object

## Returns the name to use in logging messages.

    getTaskName() : string

inherited

### Response

`string`

the name to use in logging messages.

## Logs a message with the given priority.

    log(string $msg, integer $level = \Project::MSG_INFO) : void

inherited

### Arguments

#### $msg

`string`

The message to be logged.

#### $level

`integer`

The message's priority at this message should have

## main

    main()

## References the project to the current component.

    setProject(\Project $project) : void

inherited

### Arguments

#### $project

`\Project`

The reference to the current project

## Sets the name to use in logging messages.

    setTaskName(string $name)

inherited

### Arguments

#### $name

`string`

The name to use in logging messages. Should not be `null`.

### Properties

## thenTasks

    thenTasks :

### Type(s)

``

## elseIfTasks

    elseIfTasks :

### Type(s)

``

## elseTasks

    elseTasks :

### Type(s)

``

## conditions

    conditions :

inherited

### Type(s)

``

## taskName

    taskName : string

inherited

var |

### Type(s)

`string`

## Holds a reference to the project that a project component (a task, a target, etc.) belongs to

    project : \Project

inherited

var | A reference to the current project instance

### Type(s)

`\Project`