PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

CHAPTER 15 ■ AN INTRODUCTION TO PEAR AND PYRUS


For this section, I will focus on the Pyrus mechanism for creating and hosting channels. There are
two reasons for this. First, Pyrus is the future. It is likely what we’ll all be using in the coming years. It’s
written from the ground up, without the need for backward compatibility, which makes for cruft-free
code and clean architecture. Second, the required packages are officially supported on the Pyrus site at
http://pear2.php.net. Although a perfectly good PEAR-oriented solution for channel management has
been available since 2006, it has somehow never made it from an external site
(http://greg.chiaraquartet.net) onto the PEAR website. Whatever the reasons for this, it does not inspire
confidence that the software will continue to be supported.
Still, with Pyrus so new, you may encounter some glitches along the way. Where I have to work
around rough edges, I’ll be sure to document it here.
If you're still using PEAR to build packages, don’t worry. There’s no reason why you can’t use Pyrus
channel management to serve PEAR packages. In order to create and host your own channel you will
ideally have



  • Root access to your web host computer

  • Administrative access to a web server (probably Apache) and the ability to support
    a subdomain (pear.yourserver.com, for example)


If you do not have this kind of control over your server, don’t worry, you can host your channel with
a third-party provider such as Google Code (http://code.google.com). However you decide to host it,
first of all you will need to define your channel and add some packages to it.


Defining a Channel with PEAR2_SimpleChannelServer


PEAR2_SimpleChannelServer is actually something of a misnomer. It is a tool for defining and channel
and organizing your package files ready for serving, rather than a server or server component.
At the time of this writing, the Pyrus website claims that you should use Pyrus itself to install
PEAR2_SimpleChannelServer. In fact, this currently causes an error. However, you can get the package
in a phar file at http://pear2.php.net/get/PEAR2_SimpleChannelServer-0.1.0.phar


■Note You’ll likely find that PEAR2_SimpleChannelServer installation will be improved. Check in at


http://pear2.php.net/PEAR2_SimpleChannelServer to monitor progress.


Once you have phar file you can place it somewhere central, and rename it for convenience (I chose
/usr/share/pearscs.phar). Then you can run it to set up your basic channel environment.


php /usr/share/pearscs.phar create pear.appulsus.com "Appulsus PHP repository" appulsus


Created pear.appulsus.com
| ./channel.xml
| ./rest/
| ./get/


The create subcommand requires a channel name, which is usually a host and subdomain (I’ll
return to that), a summary, and, optionally, an alias. If you omit the alias, the system will suggest one
taken from the name argument. As you can see I chose 'appulsus'. It then creates a file named

Free download pdf