Phing

Posts about the PHP build package Phing

Phing Logo

Using Custom Properties In Phing

8th January 2009 - 3 minutes read time

Phing allows you to set up certain parameters that can be used throughout the rest of the script. These might be used to define a non standard build directory, or to store database connection details that can be written to the connection file during the build.

Properties are defined using the property element, which you should place at the top of your build.xml file in order to make it easy for other developers to see what is going on. The following example defines a property and the uses the main target to print the property out.

Phing Logo

Using Patternset With Fileset In Phing

7th January 2009 - 2 minutes read time

When a project gets complicated then so to can the build.xml file associated with it. You might find it necessary to have multiple different filesets, each of which do something different, but all of which have the same core files that they use. Multiple filesets are useful if you want to create a version of your project with all of the testing files in place so that it can be tested by external developers.

Creating multiple filesets can create problems, one of which is maintenance. Confusion can also occur even if you have a single large fileset where lots of different rules for including and excluding files are defined.

This is where the patternset element comes in. You can create a set of reusable file lists that can be used by more than one fileset, but which also makes maintenance a little easier.

The following snippet shows two patternset elements that show include files and exclude files.

Phing Logo

Copying Files Using Phing

6th January 2009 - 4 minutes read time

One of the main reasons to use Phing is to create a copy of your project in another directory that you can then use as your distribution copy. Your working directory might contain lots of testing code that is not needed in the final build.

To copy a file from one directory to another using Phing you need to use the copy element. Here is a simple example where a single file is copied from one directory to another.

Phing Logo

Introduction To The Phing build.xml File

5th January 2009 - 4 minutes read time

By default, Phing will look for a file in the current working directory called build.xml when you run it. This document tells Phing what it will be doing during the build. You can change this by using the -f or the -buildfile property of phing and giving the build file as the parameter. The following code makes phing look for a build file called wibble.xml.

  1. phing -f wibble.xml

Assuming that the project is called myProject, then a minimal buildfile would be look like the following.

Phing Logo

Getting And Installing Phing

2nd January 2009 - 2 minutes read time

To get Phing you will need to have PEAR installed along with PHP. On a Windows system you can install PEAR by running the go-pear.bat file and running through the prompts there.

To get Phing just run the following commands.

  1. pear channel-discover pear.phing.info
  2. pear install --alldeps phing/phing

You should see the install output looking like this:

Phing Logo

Automated Build With Phing

2nd January 2009 - 2 minutes read time

Phing is a PHP tool that allows you to build projects. Phing stands for PHing Is Not Gnu make, which is kind of a common coder's joke. It is basically a tool that will take a set of files in multiple directories and create either a zip file or a numerous other things that you might want to do with a project.

Phing itself is a PHP program, so all that is needed to run it is a working copy of PHP. Also, because Phing is part of PEAR it is easy to install, and you don't need to install Apache to run it.

Over the next few posts I will be talking about the sort of things you can do with Phing, how to install it, how to create zip files and how to use variables to simplify things. I will add a list here for each of the posts.