PHP Objects, Patterns and Practice (3rd edition)

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

As you can see, Phing is lost without instructions. By default, it will look for a file called build.xml.
Let’s build a minimal document so that we can at least make that error message go away:


<?xml version="1.0"?>






This is the bare minimum you can get away with in a build file. If we save the previous example as
build.xml and run phing again, we should get some more interesting output:


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


megaquiz > main:


BUILD FINISHED


Total time: 0.1107 seconds


A lot of effort to achieve precisely nothing, you may think, but we have to start somewhere! Look
again at that build file. Because we are dealing with XML, I include an XML declaration. As you probably
know, XML comments look like this:



The second line in my build file is ignored. You can put as many comments as you like in your build
files, and as they grow, you should make full use of this fact. Large build files can be hard to follow
without suitable comments.
The real start of any build file is the project element. The project element can include up to four
attributes. Of these, name and default are compulsory. The name attribute establishes the project’s name;
default defines a target to run if none are specified on the command line. An optional description
attribute can provide summary information. You can specify the context directory for the build using a
basedir attribute. If this is omitted, the current working directory will be assumed. You can see these
attributes summarized in Table 19–1.


Table 19–1. The Attributes of the project Element


Attribute Required Description Default Value

Name Yes The name of the project None

Description No A brief project summary None

Default Yes The default target to run None

Basedir No The file system context in which build will run Current directory (.)

Once I have defined a project element, I must create at least one target—the one I reference in the
default attribute.

Free download pdf