CHAPTER 19 ■ AUTOMATED BUILD WITH PHING
Properties
Phing allows you to set such values using the property element.
Properties are similar to global variables in a script. As such, they are often declared toward the top
of a project to make it easy for developers to work out what’s what in the build file. Here I create a build
file that works with database information:
<?xml version="1.0"?>
<project name="megaquiz"
default="main"
I introduced a new element: property. property requires name and value attributes. Notice also that
I have added to the main target. echo is an example of a task. I will explore tasks more fully in the next
section. For now, though, it’s enough to know that echo does exactly what you would expect—it causes
its contents to be output. Notice the syntax I use to reference the value of a property here: by using a
dollar sign, and wrapping the property name in curly brackets, you tell Phing to replace the string with
the property value.
${propertyname}
All this build file achieves is to declare three properties and to print them to standard output. Here it
is in action:
$ phing
Buildfile: /home/bob/working/megaquiz/build.xml
megaquiz > main:
[echo] database: megaquiz
[echo] pass: default
[echo] host: localhost
BUILD FINISHED
Total time: 0.4402 seconds
Now that I have introduced properties, I can wrap up my exploration of targets. The target element
accepts two additional attributes: if and unless. Each of these should be set with the name of a property.
When you use if with a property name, the target will only be executed if the given property is set. If the