#native_company# #native_desc#
#native_cta#

Creating a Simple Extendable Module System

By Scott Meyers
on December 21, 2004

Creating a Simple Extendable Module System

Many web pages these days contain a sidebar filled with all sorts of goodies:?? Calendars, Searches, Links, RSS News feeds, etc. For those DIYers this can get sort of ugly if you are sticking all of these into a single php document.?? What we are going to show you in this article is how to create a simple way to import these types of features as self contained modules. First we’ll start real simple, then cover a few ways to expand this.

What you’ll need

Essentially you need a basic PHP enabled website (doh!), additionally for this lesson you’ll need the File_Find class available from PEAR. File_Find is going to help us read in our modules. There are other ways to do this that aren’t too difficult, but there is no reason to reinvent the wheel either.

Getting File_Find with PEAR

Provided you have pear properly installed, getting File_Find is rather trivial. To give it a check try typing pear at the command line. Just typing pear should result in the a print out some help options for using PEAR. For example:
stitch:~ scott$ pear

Usage: pear [options] command [command-options] 

Type "pear help options" to list all options.

Type "pear help " to get the help for the 
specified command.

Commands:

build????????????????Build an Extension From C Source

bundle??????????????Unpacks a Pecl Package

clear-cache?? Clear XML-RPC Cache

config-get??????Show One Setting

config-help????Show Information About Setting

config-set??????Change Setting

config-show????Show All Settings

cvsdiff????????????Run a "cvs diff" for all files in a 
package

cvstag??????????????Set CVS Release Tag

download??????????Download Package

download-all??Downloads each available package from 
master_server

info??????????????????Display information about a package

install????????????Install Package

list??????????????????List Installed Packages

list-all??????????List All Packages

list-upgrades??List Available Upgrades

login????????????????Connects and authenticates to remote 
server

logout??????????????Logs out from the remote server

makerpm????????????Builds an RPM spec file from a PEAR 
package

package?????????? Build Package

package-dependencies??Show package dependencies

package-validate??Validate Package Consistency

remote-info????Information About Remote Packages

remote-list????List Remote Packages

run-tests????????Run Regression Tests

search??????????????Search remote package database

shell-test??????Shell Script Test

sign??????????????????Sign a package distribution file

uninstall????????Un-install Package

upgrade????????????Upgrade Package

upgrade-all????Upgrade All Packages

If you get that, or something similar, we can assume that PEAR is installed. Now to install File_Find, simply type:
stitch:~ scott$ sudo pear install File_Find????

Password:

downloading File_Find-0.2.0.tgz ...

Starting to download File_Find-0.2.0.tgz 
(3,245 bytes)

....done: 3,245 bytes

install ok: File_Find 0.2.0

(Note the sudo, you’ll likely need administrative rights to install classes with PEAR. If you don’t, you can still download the PEAR classes individually, and install them in a local php include directory.)

Finally to make sure everything worked like it should we can list our installed PEAR classes and make sure File_Find is there:
stitch:~ scott$ pear list

Installed packages:

===================

Package?????????????? Version State

Archive_Tar?????? 1.2???????? stable

Console_Getopt 1.2???????? stable

DB???????????????????????? 1.6.8???? stable

File_Find?????????? 0.2.0???? stable

HTTP???????????????????? 1.3.3???? stable

Mail???????????????????? 1.1.4???? stable

Net_SMTP???????????? 1.2.6???? stable

Net_Socket???????? 1.0.2???? stable

PEAR???????????????????? 1.3.3.1 stable

SQLite???????????????? 1.0?? ??????stable

XML_Parser???????? 1.2.1???? stable

XML_RPC?????????????? 1.1.0???? stable

Alas, everything looks right.