Zend Framework  1.12
Public Member Functions | Protected Attributes | List of all members
Zend_Loader_Autoloader_Resource Class Reference

Public Member Functions

 __construct ($options)
 Constructor.
 
 __call ($method, $args)
 Overloading: methods.
 
 getClassPath ($class)
 Helper method to calculate the correct class path.
 
 autoload ($class)
 Attempt to autoload a class.
 
 setOptions (array $options)
 Set class state from options.
 
 setNamespace ($namespace)
 Set namespace that this autoloader handles.
 
 getNamespace ()
 Get namespace this autoloader handles.
 
 setBasePath ($path)
 Set base path for this set of resources.
 
 getBasePath ()
 Get base path to this set of resources.
 
 addResourceType ($type, $path, $namespace=null)
 Add resource type.
 
 addResourceTypes (array $types)
 Add multiple resources at once.
 
 setResourceTypes (array $types)
 Overwrite existing and set multiple resource types at once.
 
 getResourceTypes ()
 Retrieve resource type mappings.
 
 hasResourceType ($type)
 Is the requested resource type defined?
 
 removeResourceType ($type)
 Remove the requested resource type.
 
 clearResourceTypes ()
 Clear all resource types.
 
 setDefaultResourceType ($type)
 Set default resource type to use when calling load()
 
 getDefaultResourceType ()
 Get default resource type to use when calling load()
 
 load ($resource, $type=null)
 Object registry and factory.
 

Protected Attributes

 $_basePath
 
 $_components = array()
 
 $_defaultResourceType
 
 $_namespace
 
 $_resourceTypes = array()
 

Constructor & Destructor Documentation

__construct (   $options)

Constructor.

Parameters
array | Zend_Config$optionsConfiguration options for resource autoloader
Returns
void

Member Function Documentation

__call (   $method,
  $args 
)

Overloading: methods.

Allow retrieving concrete resource object instances using 'get<Resourcename>()' syntax. Example: $loader = new Zend_Loader_Autoloader_Resource(array( 'namespace' => 'Stuff_', 'basePath' => '/path/to/some/stuff', )) $loader->addResourceType('Model', 'models', 'Model');

$foo = $loader->getModel('Foo'); // get instance of Stuff_Model_Foo class

Parameters
string$method
array$args
Returns
mixed
Exceptions
Zend_Loader_Exceptionif method not beginning with 'get' or not matching a valid resource type is called
addResourceType (   $type,
  $path,
  $namespace = null 
)

Add resource type.

Parameters
string$typeidentifier for the resource type being loaded
string$pathpath relative to resource base path containing the resource types
null | string$namespacesub-component namespace to append to base namespace that qualifies this resource type
Returns
Zend_Loader_Autoloader_Resource
addResourceTypes ( array  $types)

Add multiple resources at once.

$types should be an associative array of resource type => specification pairs. Each specification should be an associative array containing minimally the 'path' key (specifying the path relative to the resource base path) and optionally the 'namespace' key (indicating the subcomponent namespace to append to the resource namespace).

As an example: $loader->addResourceTypes(array( 'model' => array( 'path' => 'models', 'namespace' => 'Model', ), 'form' => array( 'path' => 'forms', 'namespace' => 'Form', ), ));

Parameters
array$types
Returns
Zend_Loader_Autoloader_Resource
autoload (   $class)

Attempt to autoload a class.

Parameters
string$class
Returns
mixed False if not matched, otherwise result if include operation

Implements Zend_Loader_Autoloader_Interface.

clearResourceTypes ( )

Clear all resource types.

Returns
Zend_Loader_Autoloader_Resource
getBasePath ( )

Get base path to this set of resources.

Returns
string
getClassPath (   $class)

Helper method to calculate the correct class path.

Parameters
string$class
Returns
False if not matched other wise the correct path
getDefaultResourceType ( )

Get default resource type to use when calling load()

Returns
string|null
getNamespace ( )

Get namespace this autoloader handles.

Returns
string
getResourceTypes ( )

Retrieve resource type mappings.

Returns
array
hasResourceType (   $type)

Is the requested resource type defined?

Parameters
string$type
Returns
bool
load (   $resource,
  $type = null 
)

Object registry and factory.

Loads the requested resource of type $type (or uses the default resource type if none provided). If the resource has been loaded previously, returns the previous instance; otherwise, instantiates it.

Parameters
string$resource
string$type
Returns
object
Exceptions
Zend_Loader_Exceptionif resource type not specified or invalid
removeResourceType (   $type)

Remove the requested resource type.

Parameters
string$type
Returns
Zend_Loader_Autoloader_Resource
setBasePath (   $path)

Set base path for this set of resources.

Parameters
string$path
Returns
Zend_Loader_Autoloader_Resource
setDefaultResourceType (   $type)

Set default resource type to use when calling load()

Parameters
string$type
Returns
Zend_Loader_Autoloader_Resource
setNamespace (   $namespace)

Set namespace that this autoloader handles.

Parameters
string$namespace
Returns
Zend_Loader_Autoloader_Resource
setOptions ( array  $options)

Set class state from options.

Parameters
array$options
Returns
Zend_Loader_Autoloader_Resource
setResourceTypes ( array  $types)

Overwrite existing and set multiple resource types at once.

See Also
Zend_Loader_Autoloader_Resource::addResourceTypes()
Parameters
array$types
Returns
Zend_Loader_Autoloader_Resource

Member Data Documentation

$_basePath
protected
$_components = array()
protected
$_defaultResourceType
protected
$_namespace
protected
$_resourceTypes = array()
protected