Sometimes, there are pieces of software, which are unfairly forgotten. Let’s talk about one these.

Often, while working on software projects, one finds, that there are repetitive tasks, which would be much easier to deal with, if automated. In the C/Unix world, this task is often solved by Make), Java programmers prefer Apache Ant), Ruby programmers use Rake). The fact, which is not commonly known, is, that PHP also has such instrument, and it is called Pake. It was originally created by authors of Symfony framework. Unfortunately, they never wrote any documentation, which killed adoption rates.

To start automating something, you need to create Pakefile.php in the root-directory of your project, define some tasks inside and run them with “pake taskname” from command-line. The good news is, that tasks are defined in PHP language and syntax is quite simple:

<?php

pake_desc(‘FOO task’);

pake_task(‘foo’, ‘bar’);

pake_desc(‘BAR task’);

pake_task(‘bar’, ‘baz’);

pake_desc(‘BAZ task’);

pake_task(‘baz’);

pake_alias(‘default’, ‘foo’); // marking foo as default task

function run_foo($task, $args)

{

echo “foo

”;

}

function run_bar($task, $args)

{

echo “bar

”;

}

function run_baz($task, $args)

{

echo “baz

”;

}

I defined 3 rules, gave them descriptions and specified dependencies. Additionally, I specifed default rule. Now, we can play with this a bit. Create file with this contents, save it somewhere, and point your terminal to the same directory.

`

pake baz bar foo `

What happened? Pake looks for “default” task in the pakefile. We defined “foo” as default. Pake found out, that foo depends on bar, and bar depends on baz. So, Pake runs “baz”, then “bar” and then, finally, “foo”. That is as simple as it can be.

Pake has builtin support for basic file-operations (pake_mkdirs(), pake_copy(), pake_rename(), pake_remove()), which are the powered-up versions of php’s filesystem-functions, templating (pake_replace_tokens()), directory-mirroring (pake_mirror()) and runners for creating PEAR-packages, Phing-commands and Simpletest.

Pake project wasn’t maintained for a while, so I decided to give it a spin (as there is a good chance, that I will be able to use it for my current projects). I imported it’s version history to GitHub. You can find latest version here: http://github.com/indeyets/pake

My plan is to add some generally usable helpers to current branch, write some documentation and then to start work on Pake2 which would use all new features of PHP-5.3 (namespaces, closures, rich SPL).

Git-project is a source for creating pear-package. To build one use the following command:

`

php bin/pake.php release 1.1.0a1 `

it will create “pake-1.1.0a1.tgz” file in the same directory. You can install it with the following command:

`

pear install -f pake-1.1.0a1.tgz `

If you want to grab a prebuild pear-package of pake, you can do it here