PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

CHAPTER 19 ■ AUTOMATED BUILD WITH PHING


megaquiz > main:
...
[echo] pass: whooshpoppow


BUILD FINISHED


Total time: 0.2852 seconds


So now you have seen three ways of setting a property: the property element, a command line
argument, and an environment variable.
You can use targets to ensure that properties are populated. Let’s say, for example, that my project
requires a dbpass property. I would like the user to set dbpass on the command line (this always has
priority over other property assignment methods). Failing that, I should look for an environment
variable. Finally, I should give up and go for a default value:


<?xml version="1.0"?>



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











pass: ${dbpass}


So, as usual, the default target main is invoked first. This has a dependency set, so Phing goes back to
the setpass target. setpass, though, depends on setenvpass, so I start there. setenvpass is configured to
run only if dbpass has not been set and if env.DBPASS is present. If these conditions are met, then I set the
dbpass property using the property element. At this stage then, dbpass is populated either by a
command-line argument or by an environment variable. If neither of these were present, then the
property remains unset at this stage. The setpass target is now executed, but only if dbpass is not yet
present. In this case, it sets the property to the default string: "default".


Types


You may think that having looked at properties, you are now through with data. In fact, Phing
supports a set of special elements called types that encapsulate different kinds of information useful
to the build process.

Free download pdf