Out of the box, Phing provides numerous features for creating high-powered source code management scripts. In an earlier post, I talked about metaprogramming in Phing, merely scratching the surface of what Phing can do. In this article, I want to illustrate how easy it is to extend Phing.
Phing can move, copy, package, unpackage, modify, touch, and delete files. But one thing it can't do out of the box is download files. In this short article, I will illustrate how easy it is to build a new Phing task to download a file from an arbitrary URL.
The desired goal it to make it possible to write a phing task that looks like this (in the build.xml):
<download url="http://example.com/mypackage.tgz" tofile="SomeFile.tgz"/>
This task, when executed, should download the package from the target url and, if tofile is set, store the file with the name given there.
Doing this is going to involve two parts:
- Writing the task in PHP.
- Telling Phing, in the build.xml, where the new task is.
The first part is the harder of the two... it'll take a couple dozen lines of very basic code.