PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 15 ■ AN INTRODUCTION TO PEAR AND PYRUS









The installconditions element can be used to determine the phprelease element that is executed.
It accepts the specifier elements os, extension, arch, and php. These elements work in the same way as
their dependency namesakes. As well as providing phprelease elements qualified by installconditions,
you can provide a default version to be executed if none of the others are matched.
Let’s focus on the unix phprelease. The install element specifies that the file dialekt.sh should be
renamed dialekt on installation.
I specify that my data files should be installed without the .txt suffix. I do not need to specify the
dialekt subdirectory—this is automatically included for files with a data role. Note that the install
element’s as element also strips out the leading directory data that we specified in the contents element
for these files. This means that they are installed as /dialekt/dalek and


/dialekt/alig.
Note also that in Unix mode I don’t want to install the dialekt.bat script file. The ignore element
takes care of that. All being well our package is ready to install locally.

Preparing a Package for Shipment


Now that I have created my package and created a package.xml file,, it is time to generate an archived
and compressed product.
There is a single PEAR command to achieve this. We ensure we are in the root directory of our
project and run this subcommand:


$ pear package package.xml
Analyzing Dialekt/AliG.php
Analyzing Dialekt/Dalek.php
Analyzing cli-dialekt.php
Analyzing Dialekt.php
Package Dialekt-1.2.1.tgz done


This will generate a tarred and gzipped archive (including all referenced files as well as the
package.xml file itself) suitable for distribution. You can make this available for straight download. If you
have dependencies between packages, you can reference URIs in your package elements and use the uri
element in place of channel. If you are offering many interdependent packages to your users, though,
perhaps you should consider taking things to the next level.


Setting Up Your Own Channel


Why set up your own channel? Aside from the sheer coolness of such a thing, the main benefits lie in
PEAR’s automatic dependency management and the consequent ease of installation and upgrade for
your users. It’s easy enough for a user to install a single package using a full path to a tarball URL. If you
have designed a library system in tiers working from low-level utility packages to high-level applications,
things become more complicated. It can be a real pain for users to manage multiple interdependent
packages on their systems, especially as they evolve.

Free download pdf