Sams Teach Yourself PHP and MySQL: PHP Extension and Application Repository (PEAR)
June 02, 2009
|
Learn about PEAR, a framework and distribution system for reusable PHP packages.
|
Introducing PEAR
PEAR is a framework and distribution system for reusable
PHP packages. PEAR is made up of the following:
- A structured library of open-source code for PHP developers
- A system for distributing and maintaining code in packages
- The PEAR Coding Standards (PCS)
- The PHP Foundation Classes (PFC)
- Online support for the PEAR community through a website and mailing list
The PEAR Code Library
PEAR brings together many different open-source projects,
each of which is bundled into its own package. Each PEAR
package has its own maintainers and developers, who
determine the changes and release cycle for their own
packages, but the package structure is consistent for all
PEAR projects.
You use the PEAR installer, which is shipped with PHP, to
automatically download and install a PEAR package by simply
giving its name. You will learn how to use the PEAR
installer later in this lesson.
Each package may have dependencies from other PEAR
packages, and this is explicitly noted in the documentation,
even if packages appear to be related because of their
names.
A package tree structure exists within PEAR, and an
underscore character (_) separates nodes in the hierarchy.
For instance, the HTTP package contains various HTTP
utilities, whereas HTTP_Header deals specifically with HTTP
header requests.
Package Distribution and Maintenance
PEAR packages are registered in a central database at http://pear.php.net. The PEAR
website provides a searchable interface to the database by
package name, category, and release date.
Maintainers of PEAR packages use the PEAR website to
manage their projects. A CVS server allows developers to
collaborate on source code and, once a release has been
agreed upon, it can be made available from this central
location immediately.
PEAR Coding Standards
The PCS documents were created because many different
teams are developing open-source packages that might be of
use to the PHP community.
The documents in PCS outline a structured way in which
code should be written in order for a package to be accepted
as part of the PEAR project. The standards are quite
detailed and contain mostly points of style, such as
identifier naming conventions and a consistent style to use
when declaring functions and classes.
This may sound a little daunting, but as your scripts
become more complicated, you will realize how important it
is to write readable code, and you will begin to develop a
clear coding style. The PCS documentation simply formalizes
a set of guidelines for writing readable PHP.
You can find the PCS documents online at http://
pear.php.net/manual/en/standards.php.
Sams Teach Yourself PHP and MySQL: PHP Extension and Application Repository (PEAR)
Finding a PEAR Package
|