A custom resource plugin for populating the registry
Saturday, August 14, 2010
This post looks at a simple custom resource plugin that I’ve recently created for populating the registry with values from the application configuration file. I have already examined adding a Log plugin and a View plugin in previous posts; the basic technique for adding this one is the same.
First we need a line like this in the configuration file to allow the bootstrapper to find our plugin:
pluginPaths.Application_Resource = APPLICATION_PATH "/resources"
The key Application_Resource indicates the prefix given to the class that implements the plugin, minus its trailing underscore. The value indicates the location in which the plugins with this prefix are stored.
The class itself is implemented in Registry.php in the resources directory. It contains the following code:
<?php class Application_Resource_Registry extends Zend_Application_Resource_ResourceAbstract { public function init() { // Get the registry object $registry = Zend_Registry::getInstance(); // Get the options that should be placed in the registry $options = $this->getOptions(); // Add the options to the registry foreach ($options as $index => $value) { $registry->set($index, $value); } return $registry; } }
The code should be fairly self-explanatory. The options are key/value pairs retrieved from the configuration file, e.g.
resources.registry.phone = "phone number"
In the above case, the value “phone number” is stored under the index phone in the registry.

Practical Web 2.0 Applications with PHP (Expert's Voice) by Quentin Zervaas
Beginning Databases with PostreSQL: From Expert to Professional 2nd Edition: From Novice to Professional by Neil Matthew, Richard Stones
[...] http://zf.gm-ram.com/posts/a-custom-resource-plugin-for-populating-the-registry/ [...]
[...] touched on some of the things I have been adding to the site; see the post on pagination, the post on a plugin to populate the registry and the post on automatically generating a sitemap. I intend to do some further posts on the new [...]