View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}




1.0 - 1 January 2008: Initial Draft.

Zend_Loader_Autoloader_Resource is intended to simplify loading resources that do not have 1:1 class prefix/filesystem mappings. The primary use case is for use with modular applications, to allow autoloading of module-specific classes.

* [Pastebin resource loader implementation|]
* [Zend_Controller_Action_Helper_ResourceLoader proposal|]

* This component *will* implement Zend_Loader_Autoloader_Interface.
* This component *will* require specification of both a prefix and base directory
* This component *will* provide default component/subdirectory mappings
** Users *will* be able to register custom component/subdirectory mappings
** This component *will* allow autoloading arbitrarily nested classes under existing component maps
* This component *should* also act as an object factory and registry for the given resource namespace

* Zend_Loader_Exception
* [Zend_Loader_Autoloader|ZFPROP:Zend_Loader_Autoloader - Ralph Schindler]

Typically, this component will be instantiated in a module's bootstrap. It's purpose is to provide the ability to autoload components in that subdirectory, assuming a standard directory layout.

For instance, the bootstrap might do the following:
$autoloader = new Zend_Loader_Autoloader_Resource(array(
'prefix' => 'Spindle',
'basePath' => realpath(dirname(__FILE__)),

This would then allow your module code to use autoloading to arbitrary resources. For instance, the following directory structure would establish the associated classes:
Bug.php // Spindle_Model_Bug
Bug.php // Spindle_Form_Bug
When the resource autoloader is in play, you can simply instantiate these classes, without worrying where they are:
$form = new Spindle_Form_Bug();

* Milestone 1: \[DONE\] Proposal created
* Milestone 2: \[DONE\] Working prototype checked into public repository
* Milestone 3: Community review of proposal
* Milestone 4: Proposal acceptance
* Milestone 5: Passing unit tests and initial documentation committed to incubator
* Milestone 6: Review for inclusion in trunk

* Zend_Loader_Autoloader_Resource

Basic usage:
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'prefix' => 'Spindle',
'basePath' => realpath(dirname(__FILE__)),

Using as an object factory and registry:
/* Spindle_Model_Bug */
$bugModel = $resourceLoader->getModel('bug');

Registering custom resource paths:
// Adds 'validators' resource, mapping to basePath + /validators, using prefix
// $prefix _Validate.
$resourceLoader->addResourceType('validator', 'validators', 'Validate');

// e.g., this loads the class from
// application/modules/spindle/validators/Foo.php
$foo = new Spindle_Validate_Foo();

class Zend_Loader_Autoloader_Resource implements Zend_Loader_Autoloader_Interface
public function __construct($options);

public function initDefaultResourceTypes();

public function __call($method, $args);

public function autoload($class);

public function setOptions(array $options);

public function setPrefix($prefix);

public function getPrefix();

public function setBasePath($path);

public function getBasePath();

public function addResourceType($type, $path, $prefix = null);

public function addResourceTypes(array $types);

public function setResourceTypes(array $types);

public function getResourceTypes();

public function hasResourceType($type);

public function removeResourceType($type);

public function clearResourceTypes();

public function setDefaultResourceType($type);

public function getDefaultResourceType();

public function load($resource, $type = null);