In my Beyond Frameworks talk, I explained how a component-based architecture can help answer some of the important (i.e. expensive!) questions you might face when creating long-lived apps that rely on a PHP framework. In this series of blog posts, I’m going to look at how to go about creating and working with components.
This page has been updated with the latest information about phix.
phix is a small command-line tool for PHP applications. I created it to fix (pun intended) the problem of how to easily automate the tasks involved in creating and (especially) maintaining components. These tasks aren’t built into phix; they are commands that ship with the phix distribution. You can create your own commands to run inside phix too, and it’s easy to do so.
What Can phix Do?
Running phix without any command-line parameters gives us a basic overview of what it can do:
phix 0.13.2 - http://www.phix-project.org Copyright (c) 2011 Stuart Herbert and contributors Released under the BSD license SYNOPSIS /usr/bin/phix [ -?dhv ] [ --? --debug --help --version ] [ -I<path> ] [ --include=<path> ] [ command ] [ command-options ] OPTIONS Use the following switches in front of any <command> to have the following effects. -? | -h display a summary of the command-line structure -I<path> | --include=<path> add a folder to load commands from phix finds all of its commands by searching PHP's include_path for PHP files in folders called 'PhixCommands'. If you want to phix to look in other folders without having to add them to PHP's include_path, use --include to tell phix to look in these folders. phix expects '<path>' to point to a folder that conforms to the PSR0 standard for autoloaders. For example, if your command is the class 'MeToolsPhixCommands ScheduledTask', phix would expect to autoload this class from the 'Me /Tools/PhixCommands/ScheduledTask.php' file. If your class lives in the './myApp/lib/Me/Tools/PhixCommands' folder, you would call phix with 'phix --include=./myApp/lib' -d | --debug enable debugging output -v | --version display phix version number --? | --help display a full list of supported commands COMMANDS help # get detailed help about a specific phix command pear:expand-package-xml # expand the tokens and contents of the PEAR-compatible package.xml file pear:register-channels # register the channels for the dependencies listed in the PEAR-compatible package.xml file php-library:init # initialise the directory structure of a php-library component php-library:status # check the status of a php-library component php-library:upgrade # upgrade the structure of a php-library component to the latest version See /usr/bin/phix help <command> for detailed help on <command>
phix ships with easy-to-use commands for creating and maintained packaged components of PHP code. Additional commands will be added in the future!
You can add your own commands to this list with minimal effort, something we’ll look at in a later blog post. By default, phix searches your PHP include_path for new PhixCommands namespaces to load; you can also use the -I flag to tell it to search a specific PSR-0 compatible class tree if needed.
And the best thing of all is that phix is framework-agnostic; it isn’t going to break as you upgrade or change frameworks – an important requirement for creating and working with components!
phix comes with a built-in help command to show you what any single command can do. And best of all, it automatically tells you where the code is for that command, so if something isn’t working or you want to enhance it, you don’t have to wonder where phix is getting the code from:
$ phix help php-library:init NAME /usr/bin/phix php-library:init - initialise the directory structure of a php-library component SYNOPSIS /usr/bin/phix php-library:init <folder> OPTIONS <folder> <folder> is a path to an existing folder, which you must have permission to write to. IMPLEMENTATION This command is implemented in the PHP class: * Phix_ProjectComponentMakerPhixCommandsPhpLibraryInit which is defined in the file: * /usr/share/php/Phix_Project/ComponentMaker/PhixCommands/PhpLibraryInit .php
Where To Find Further Information
The Phix Project website is the official homepage for the project. Hopefully you’ll be able to find everything you need from there.
Stuart’s PHP Components blog posts provide a step-by-step look at using phix to create and maintain packaged components of PHP code.14 comments »