PHP Objects, Patterns and Practice (3rd edition)

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

Delete


Installation is generally about creating, copying, and transforming files. Deletion has its place as well,
though. This is particularly the case when you wish to perform a clean install. As I have already
discussed, files are generally only copied from source to destination for source files that have changed
since the last build. By deleting a build directory, you ensure that the full compilation process will take
place.
Here I delete a directory:





When I run phing with the argument clean (the name of the target), my delete task element is
invoked. Here’s Phing’s output:


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


megaquiz > clean:
[delete] Deleting directory /home/bob/working/megaquiz/build


BUILD FINISHED


The delete element accepts an attribute, file, which can be used to point to a particular file.
Alternatively, you can fine-tune your deletions by adding a fileset subelement to delete.


Summary


Serious development rarely happens all in one place. A codebase needs to be separated from its
installation, so that work in progress does not pollute production code that needs to remain functional
at all times. Version control allows developers to check out a project and work on it in their own space.
This requires that they should be able to configure the project easily for their environments. Finally, and
perhaps most importantly, the customer (even if the customer is yourself in a year’s time, when you’ve
forgotten the ins and outs of your code) should be able to install your project after a glance at a Read Me
file.
In this chapter, I have covered some of the basics of Phing, a fantastic tool, which brings much of
the functionality of Apache Ant to the PHP world. I have only scratched the surface of Phing’s
capabilities. Nevertheless, once you are up and running with the targets, tasks, types, and properties
discussed here, you’ll find it easy to bolt on new elements for advanced features, like creating
tar/gzipped distributions, automatically generating PEAR package installations, and running PHP code
directly from the build file.
If Phing does not satisfy all your build needs, you will discover that, like Ant, it is designed to be
extensible—get out there and build your own tasks! Even if you don’t add to Phing, you should take
some time out to examine the source code. Phing is written entirely in object-oriented PHP, and its code
is chock full of design examples.

Free download pdf