Elegant Runtime Configuration

While working on a unit test facility for the “Joomla!” project, one of the developers made me aware of functions in the “Standard PHP Library” that let you do some powerful things with class auto-loading.

One of the biggest challenges with code libraries is making them easy to configure in a wide range of server environments. PEAR is a large, powerful set of packages that is useful in just about any application, but getting the installation right can be a real pain, particularly in shared hosting environments.

The SPL allows an application to manipulate a stack of auto-load functions. So now to use AP5L, all you have to do is include the base AP5L.php file and then call AP5L::install(). The “installer” injects an auto-loader that recognizes all AP5L classes. Since the code for these classes is relative to the base AP5L.php, it can derive the appropriate file name from the class name with ease. If the class isn’t part of AP5L, it simply passes it along to the next loader in the stack.

AP5L::install() also has an option for a more traditional approach, adding the install path to PHP’s include file path. However this leaves the application with the responsibility of including the class files before they’re used. In highly tuned systems with performance optimizers there are some good reasons to load all classes in one shot, and this option makes that slightly easier. [If you’re really interested in performance, the best easy thing to do is to merge everything into one big file, stripped of comments and whitespace, but that’s another topic.]

RapidForm Refactored for AP5L

One day I needed a simple form for list subscription that needed a CAPTCHA image and I didn’t want to go through the trouble of trying to crowbar it into any of the “complex” PEAR form packages.

So I thought “why not build something really simple and lightweight that will create and validate a simple form?” I wanted three methods: create, validate, and save. Sweet, simple, easy to code.

That might not have been the smartest thing I ever did. (more…)

How to Completely Update an Eclipse Workspace

Over the years that I’ve been using Eclipse, my main workspace has been accumulating bit rot. Older versions of plugins have left settings around, many small configuration details have been “not quite right”, and I never really figured out how to deal with the glitches, so I just tolerated them.

But the Europa build, or PDT, or something in my configuration brought in “Buckminster”. In my workspace, Buckminster had an annoying habit of pausing for several seconds, dumping a bunch of error messages about deprecated constructs in some meta data file (to which I say “it’s your damn file, you deal with it” to no avail).

While trying to deal with a major annoyance in Eclipse, namely that settings for tabs/spaces are Workspace global (duh), I gave in to this limitation and set up a new workspace and imported some of my tab based projects. (more…)

AP5L: The Abivia PHP5 Library Now Available

This is more a case of “release prematurely, release often” than anything else, but I’ve just completed the move of my PHP5 libraries up to a Google Code repository, with a GPLv3 license attached.

The primary reason for the release is to get the generic ACL code out in the wild.

As the project description says, documentation is thin to nonexistent, and significant parts of the code are just straight copies of the equivalent PHP4 library. I’ll be “porting” code as the opportunity arises. (more…)

Abstracting Data Storage in PHP

One of the problems with so-called “generic” PHP libraries is that they frequently contain dependencies that are either in conflict with an application, or that require a large amount of duplicate code.

This really shows up in database interfaces. If the library needs to manage persistent data, then there’s going to be a database interface. There are a lot of packages out there that aim to ease the challenges of interfacing to various SQL databases. Being a fan of PEAR, I tend to use MDB2. Others use ADODB. Application frameworks such as Joomla provide their own.
(more…)

Mastodon