C H A P T E R 19
■ ■ ■
Automated Build with Phing
If version control is one side of the coin, then automated build is the other. Version control allows
multiple developers to work collaboratively on a single project. With many coders each deploying a
project in her own space, automated build soon becomes essential. One developer may have her Web-
facing directory in /usr/local/apache/htdocs; another might use /home/bibble/public_html. Developers
may use different database passwords, library directories, or mail mechanisms. A flexible codebase
might easily accommodate all of these differences, but the effort of changing settings and manually
copying directories around your file system to get things working would soon become tiresome—
especially if you need to install code in progress several times a day (or several times an hour).
You have already seen that PEAR handles installation. You'll almost certainly want to deliver a
project to an end user via a PEAR package, because that mechanism provides the lowest barrier to
installation (users will likely already have PEAR present on their systems, and PEAR supports network
installation). PEAR handles the last stages of installation admirably, but there’s a lot of work that might
need automating before a package has been created. You may want to extract files from a version control
repository, for example. You should run tests and compile files together into a build directory. Finally,
you’ll want to automate the creation of the PEAR package itself. In this chapter, I introduce you to Phing,
which handles just such jobs. This chapter will cover
- Getting and installing Phing: Who builds the builder?
- Properties: Setting and getting data.
- Types: Describing complex parts of a project.
- Targets: Breaking a build into callable, interdependent sets of functionality.
- Tasks: The things that get stuff done.
What Is Phing?
Phing is a PHP tool for building projects. It is very closely modeled on the hugely popular (and very
powerful) Java tool called Ant. Ant was so named because it is small but capable of constructing things
that are very large indeed. Both Phing and Ant use an XML file (usually named build.xml) to determine
what to do in order to install or otherwise work with a project.
The PHP world really needs a good build solution. Serious developers have had a number of options
in the past. First, it is possible to use make, the ubiquitous Unix build tool that is still used for most C and
Perl projects. However, make is extremely picky about syntax and requires quite a lot of shell knowledge,
up to and including scripting—this can be challenging for some PHP programmers who have not come
to programming via the Unix or Linux command line. What’s more, make provides very few built-in
tools for common build operations such as transforming file names and contents. It is really just a glue