Introduction:
PEAR is 'PHP Extension and Application Repository' (similar to CPAN for those perl users). It is a repository for public libraries for use with the popular PHP language, and also represents a set of PHP coding standards to encourage a unified style within the libraries.
In the past I simply wrote my own libraries for each task I wanted to accomplish, and then all my apps shared the same set of custom libs. Now, this is not a bad way to go, and you may be quite happy with the results, but if you want to use a more standardized approach, with code that has been peer reviewed and documented, then PEAR is for you.
Yawp is a framework that takes some of the base PEAR packages and combines them to use a unified config file and wrapper object. It can be a quick way to jumpstart into using a full set of PEAR packages for your application.
Installing PEAR:
If you have compiled a recent version of PHP (and not used --without-pear), then you may already have PEAR on your system. On fedora you could do:
up2date -i php-pear
Installing PEAR modules:
This bit is easy. You just need to do something like the following: (here are commands to install all the PEAR modules I'll be mentioning, and prerequisites).
pear install Auth
pear install Benchmark
pear install Cache_Lite
pear install DB
pear install DB_Table
pear install Log
pear install Var_Dump
pear install http://phpyawp.com/Yawp-1.1.0.tgz
pear install HTML_Common
pear install HTML_QuickForm
pear install HTML_Table
If PEAR complains about dependencies, then simply install the dependency packages first (unless it happens to be something like: PHP version >= 5.0.0 is required).
If you want to install a non-stable package, use the full package name with the version:
pear install HTML_Common2-0.1.0
Using PEAR:
Make sure that your PEAR repository is in your include_path. Edit php.ini and make sure you have something like this:
include_path = ".:/usr/share/pear/"
Then you can use the following from PHP:
require_once 'HTML/QuickForm.php';
PEAR References:
PEAR Manual - General information about PEAR.
PEAR Faq - Frequently Asked Questions.
Yawp Documentation - Getting started, function reference and example code for Yawp.
Package Documentation - Documentation for all PEAR packages can be found here. Find your package, then click 'Documentation', and then either 'End-User Documentation' or 'Documentation for latest release'.
Next Part:
In my next post I'll discuss using Yawp as the base framework for your web application.