PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 19 ■ AUTOMATED BUILD WITH PHING

If I had not set the override element in the second property element, the original value of "default"
would have stayed in place. It is important to note that targets are not functions: there is no concept of
local scope. If you override a property within a task, it remains overridden for all other tasks throughout
the build file. You could get around this, of course, by storing a property value in a temporary property
before overriding, and then resetting it when you have finished working locally.
So far, I have dealt with properties that you define yourself. Phing also provides built-in properties.
You reference these in exactly the same way that you would reference properties you have declared
yourself. Here’s an example:


<?xml version="1.0"?>



<project name="megaquiz"
default="main"





name: ${phing.project.name}
base: ${project.basedir}
home: ${user.home}
pass: ${env.DBPASS}


I reference just a few of the built-in Phing properties. phing.project.name resolves to the name of
the project as defined in the name attribute of the project element; project.basedir gives the starting
directory; user.home provides the executing user’s home directory (this is useful for providing default
install locations).
Finally, the env prefix in a property reference indicates an operating system environment variable.
So by specifying ${env.DBPASS}, I am looking for an environment variable called DBPASS. Here I run Phing
on this file:


$ phing
Buildfile: /home/bob/working/megaquiz/build.xml


megaquiz > main:


[echo] name: megaquiz
[echo] base: /home/bob/working/megaquiz
[echo] home: /home/bob
[echo] pass: ${env.DBPASS}


BUILD FINISHED


Total time: 0.1120 seconds


Notice that the final property has not been translated. This is the default behavior when a property
is not found—the string referencing the property is left untransformed. If I set the DBPASS environment
variable and run again, I should see the variable reflected in the output:


$ export DBPASS=wooshpoppow
$ phing
Buildfile: /home/bob/working/megaquiz/build.xml

Free download pdf