views:

146

answers:

1

Hello - I am having trouble understanding the Phing documentation regarding multiple conditions for a given <if> tag. It implies you cannot have multiple conditions unless you use the <and> tag, but there are no examples of how to use it. Consequently I nested two <if> tags, however I feel silly doing this when I know there is a better way. Does anyone know how I can use the <and> tag to accomplish the following:

  <if><equals arg1="${deployment.host.type}" arg2="unrestricted" /><then>
    <if><equals arg1="${db.adapter}" arg2="PDO_MYSQL"/><then>
      <!-- Code Here -->
    </then></if>
  </then></if>

I find it very surprising that no one has had any experience with this. Phing is an implementation of the 'ANT' build tool in PHP instead of Java. It is very useful for PHP developers who feel a lack of a simple and powerful deployment tool. Java's ability to package self contained web projects into a single file or package multiple web project files into a yet bigger file is an amazing capability. ANT or Phing does not get PHP to that point, but its a definite step in the right direction and leaps and bounds easier to understand and use than GNU Make ever was or will be.

A: 

According to the Phing documentation:

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.

It may sound confusing at first, especially with no handy examples available, but the keywords to note are, "accepts an arbitrary number of conditions as nested elements." If you try the following build snippet out, you should easily realize how to use <or> and <and> conditions:

<if>
    <or>
        <equals arg1="foo" arg2="bar" />
        <equals arg1="baz" arg2="baz" />
    </or>
    <then>
        <echo message="Foo equals bar, OR baz equals baz!" />
    </then>
</if>

<if>
    <or>
        <equals arg1="foo" arg2="bar" />
        <equals arg1="baz" arg2="bam" />
    </or>
    <then>
        <echo message="Foo equals bar, OR baz equals baz!" />
    </then>
    <else>
        <echo message="No match to OR found." />
    </else>
</if>
<fail />
dohpaz42
I see now - thank you. I think the developers at Phing should do well to include this in the documentation. Pathetically I think I tried every imaginable combination BUT this one. :)
Matt1776