Loader/Autoloader/Resource.php
Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Loader
- Subpackage
- Autoloader
- Version
- $Id: Resource.php 24593 2012-01-05 20:35:02Z matthew $
\Zend_Loader_Autoloader_Resource
Resource loader
- Implements
- \Zend_Loader_Autoloader_Interface
- Children
- \Zend_Application_Module_Autoloader
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Uses
- \global\Zend_Loader_Autoloader_Interface
Properties


array $_components = array()
array()
Details- Type
- array


string $_defaultResourceType =
- Type
- string
Methods


__call(string $method, array $args) : mixed
Overloading: methods
Allow retrieving concrete resource object instances using 'get
$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
Name | Type | Description |
---|---|---|
$method | string | |
$args | array |
Type | Description |
---|---|
mixed |
Exception | Description |
---|---|
\Zend_Loader_Exception | if method not beginning with 'get' or not matching a valid resource type is called |


__construct(array | \Zend_Config $options) : void
Constructor
Name | Type | Description |
---|---|---|
$options | array | \Zend_Config | Configuration options for resource autoloader |


addResourceType(string $type, string $path, null | string $namespace = null) : \Zend_Loader_Autoloader_Resource
Add resource type
Name | Type | Description |
---|---|---|
$type | string | identifier for the resource type being loaded |
$path | string | path relative to resource base path containing the resource types |
$namespace | null | string | sub-component namespace to append to base namespace that qualifies this resource type |
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |


addResourceTypes(array $types) : \Zend_Loader_Autoloader_Resource
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',
),
));
Name | Type | Description |
---|---|---|
$types | array |
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |


autoload(string $class) : mixed
Attempt to autoload a class
Name | Type | Description |
---|---|---|
$class | string |
Type | Description |
---|---|
mixed | False if not matched, otherwise result if include operation |


clearResourceTypes() : \Zend_Loader_Autoloader_Resource
Clear all resource types
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |


getClassPath(string $class) : False
Helper method to calculate the correct class path
Name | Type | Description |
---|---|---|
$class | string |
Type | Description |
---|---|
False | if not matched other wise the correct path |


getDefaultResourceType() : string | null
Get default resource type to use when calling load()
Type | Description |
---|---|
string | null |


hasResourceType(string $type) : bool
Is the requested resource type defined?
Name | Type | Description |
---|---|---|
$type | string |
Type | Description |
---|---|
bool |


load(string $resource, string $type = null) : object
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.
Name | Type | Description |
---|---|---|
$resource | string | |
$type | string |
Type | Description |
---|---|
object |
Exception | Description |
---|---|
\Zend_Loader_Exception | if resource type not specified or invalid |


removeResourceType(string $type) : \Zend_Loader_Autoloader_Resource
Remove the requested resource type
Name | Type | Description |
---|---|---|
$type | string |
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |


setBasePath(string $path) : \Zend_Loader_Autoloader_Resource
Set base path for this set of resources
Name | Type | Description |
---|---|---|
$path | string |
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |


setDefaultResourceType(string $type) : \Zend_Loader_Autoloader_Resource
Set default resource type to use when calling load()
Name | Type | Description |
---|---|---|
$type | string |
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |


setNamespace(string $namespace) : \Zend_Loader_Autoloader_Resource
Set namespace that this autoloader handles
Name | Type | Description |
---|---|---|
$namespace | string |
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |


setOptions(array $options) : \Zend_Loader_Autoloader_Resource
Set class state from options
Name | Type | Description |
---|---|---|
$options | array |
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |


setResourceTypes(array $types) : \Zend_Loader_Autoloader_Resource
Overwrite existing and set multiple resource types at once
Name | Type | Description |
---|---|---|
$types | array |
Type | Description |
---|---|
\Zend_Loader_Autoloader_Resource |
- See
- \global\Zend_Loader_Autoloader_Resource::addResourceTypes()