PHP Objects, Patterns and Practice (3rd edition)

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

$ phing


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


megaquiz > main:


[copy] Copying 8 files to /home/bob/working/megaquiz/build/lib
[filter:ReplaceTokens] Replaced "@dbname@" with "megaquiz"
[filter:ReplaceTokens] Replaced "@dbpass@" with "default"
[filter:ReplaceTokens] Replaced "@dbhost@" with "localhost"


BUILD FINISHED


Total time: 0.1413 seconds


The original file is untouched, of course, but thanks to the Copy task, it has been reproduced at
build/lib/Config.php:


class Config {
public $dbname ="megaquiz";
public $dbpass ="default";
public $dbhost ="localhost";
}


Not only has the comment been removed, but the tokens have been replaced with their property
equivalents.


Tasks


Tasks are the elements in a build file that get things done. You won’t achieve much without using a task,
which is why I have cheated and used a couple already. I'll reintroduce these.


Echo


The Echo task is perfect for the obligatory “Hello World” example. In the real world, you can use it to tell
the user what you are about to do or what you have done. You can also sanity-check your build process
by displaying the values of properties. As you have seen, any text placed within the opening and closing
tags of an echo element will be printed to the browser:


The pass is '${dbpass}', shhh!
Alternatively, you can add the output message to a msg attribute:


This will have the identical effect of printing the following to standard output:

[echo] The pass is 'default', shhh!


Copy


Copying is really what installation is all about. Typically, you will create one target that copies files from
your source directories and assembles them in a temporary build directory. You will then have another

Free download pdf