PHP Objects, Patterns and Practice (3rd edition)

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

When installation takes place, files of role doc, data, and test are not dropped directly into their
respective directories. Instead, a subdirectory named after the package is created in the test_dir and
data_dir directories, and files are installed into this.
In a PEAR project, everything must have a role, and every role has its place. If you do not have the
correct privileges to work with the default role locations, you can set your own locations using the pear
command line tool:


$ pear config-set php_dir ~/php/lib/


$ pear config-set data_dir ~/php/lib/data/
$ pear config-set bin_dir ~/php/bin/
$ pear config-set doc_dir ~/php/lib/doc/


$ pear config-set test_dir ~/php/lib/test/


■Note Pyrus uses set rather than config-set for the same purpose.


Now, PEAR will use your directories rather than those described in Table 15–2. Remember that if
you do this, you should add the lib directory to your include path: either in the php.ini file, an
.htaccess file, or using the ini_set() function in your scripts. You should also ensure that the bin
directory is in your shell’s path so that command line commands can be found.
My example revolves around a fictitious package called Dialekt. Here is the package’s directory and
file structure:


./package.xml
./data
./data/dalek.txt
./data/alig.txt
./script
./script/dialekt.sh
./script/dialekt.bat
./cli-dialekt.php
./Dialekt.php
./Dialekt
./Dialekt/AliG.php
./Dialekt/Dalek.php


As you can see, I have mirrored some of the standard PEAR roles in my data structure. So I include
data and script directories. The top-level directory contains two PHP files. These should be installed in
the PEAR directory (/usr/local/php/lib by default). Dialekt.php is designed to be the first port of call for
client code. The user should be able to include Dialekt with


require_once("Dialekt.php");


Additional PHP files (Dalek.php and AliG.php) are stored in a Dialekt directory that will be added to
the PEAR directory (these are responsible for the detailed process of translating web pages and text files
into oh-so-funny versions of themselves). Dialekt.php will include these on behalf of client code. So that
the installed Dialekt package will be callable from the command line, we have included a shell script that
will be moved to PEAR’s script directory. Dialekt uses configuration information stored in text files.
These will be installed in PEAR’s data directory.
Here's the full contents tag:

Free download pdf