Definition at line 35 of file Resource.php.
◆ __construct()
Constructor
- Parameters
-
array | Zend_Config | $options | Configuration options for resource autoloader |
- Returns
- void
Definition at line 68 of file Resource.php.
74 #require_once 'Zend/Loader/Exception.php'; 81 if ((
null === $namespace)
84 #require_once 'Zend/Loader/Exception.php'; 85 throw new Zend_Loader_Exception(
'Resource loader requires both a namespace and a base path for initialization');
88 if (!empty($namespace)) {
91 #require_once 'Zend/Loader/Autoloader.php'; setOptions(array $options)
◆ __call()
__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
-
- Returns
- mixed
- Exceptions
-
Definition at line 115 of file Resource.php.
117 if (
'get' == substr(
$method, 0, 3)) {
120 #require_once 'Zend/Loader/Exception.php'; 124 #require_once 'Zend/Loader/Exception.php'; 131 #require_once 'Zend/Loader/Exception.php';
load($resource, $type=null)
◆ addResourceType()
addResourceType |
( |
|
$type, |
|
|
|
$path, |
|
|
|
$namespace = null |
|
) |
| |
Add resource type
- Parameters
-
string | $type | identifier for the resource type being loaded |
string | $path | path relative to resource base path containing the resource types |
null | string | $namespace | sub-component namespace to append to base namespace that qualifies this resource type |
- Returns
- Zend_Loader_Autoloader_Resource
Definition at line 282 of file Resource.php.
285 if (!isset($this->_resourceTypes[
$type])) {
286 if (
null === $namespace) {
287 #require_once 'Zend/Loader/Exception.php'; 291 $namespace = ucfirst(trim($namespace,
'_'));
292 $this->_resourceTypes[
$type] = array(
293 'namespace' => empty($namespaceTopLevel) ? $namespace : $namespaceTopLevel .
'_' . $namespace,
296 if (!is_string(
$path)) {
297 #require_once 'Zend/Loader/Exception.php'; 302 $component = $this->_resourceTypes[
$type][
'namespace'];
303 $this->_components[$component] = $this->_resourceTypes[
$type][
'path'];
◆ addResourceTypes()
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
-
- Returns
- Zend_Loader_Autoloader_Resource
Definition at line 333 of file Resource.php.
335 foreach ($types as
$type => $spec) {
336 if (!is_array($spec)) {
337 #require_once 'Zend/Loader/Exception.php'; 340 if (!isset($spec[
'path'])) {
341 #require_once 'Zend/Loader/Exception.php'; 346 if (isset($spec[
'namespace'])) {
347 $namespace = $spec[
'namespace'];
addResourceType($type, $path, $namespace=null)
◆ autoload()
Attempt to autoload a class
- Parameters
-
- Returns
- mixed False if not matched, otherwise result if include operation
Implements Zend_Loader_Autoloader_Interface.
Definition at line 197 of file Resource.php.
200 if (
false !== $classPath) {
201 return include $classPath;
$_option $_optionId $class
◆ clearResourceTypes()
◆ getBasePath()
Get base path to this set of resources
- Returns
- string
Definition at line 269 of file Resource.php.
◆ getClassPath()
Helper method to calculate the correct class path
- Parameters
-
- Returns
- False if not matched other wise the correct path
Definition at line 141 of file Resource.php.
143 $segments = explode(
'_',
$class);
147 if (!empty($namespaceTopLevel)) {
148 $namespace = array();
149 $topLevelSegments = count(explode(
'_', $namespaceTopLevel));
150 for (
$i = 0;
$i < $topLevelSegments;
$i++) {
151 $namespace[] = array_shift($segments);
153 $namespace = implode(
'_', $namespace);
154 if ($namespace != $namespaceTopLevel) {
160 if (count($segments) < 2) {
165 $final = array_pop($segments);
166 $component = $namespace;
169 $segment = array_shift($segments);
170 $component .= empty($component) ? $segment :
'_' . $segment;
171 if (isset($this->_components[$component])) {
172 $lastMatch = $component;
174 }
while (count($segments));
180 $final = substr(
$class, strlen($lastMatch) + 1);
181 $path = $this->_components[$lastMatch];
182 $classPath =
$path .
'/' . str_replace(
'_',
'/', $final) .
'.php';
static isReadable($filename)
$_option $_optionId $class
◆ getDefaultResourceType()
getDefaultResourceType |
( |
| ) |
|
Get default resource type to use when calling load()
- Returns
- string|null
Definition at line 435 of file Resource.php.
◆ getNamespace()
Get namespace this autoloader handles
- Returns
- string
Definition at line 247 of file Resource.php.
◆ getResourceTypes()
Retrieve resource type mappings
- Returns
- array
Definition at line 372 of file Resource.php.
◆ hasResourceType()
Is the requested resource type defined?
- Parameters
-
- Returns
- bool
Definition at line 383 of file Resource.php.
385 return isset($this->_resourceTypes[
$type]);
◆ load()
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
-
Definition at line 452 of file Resource.php.
454 if (
null ===
$type) {
457 #require_once 'Zend/Loader/Exception.php'; 462 #require_once 'Zend/Loader/Exception.php'; 465 $namespace = $this->_resourceTypes[
$type][
'namespace'];
467 if (!isset($this->_resources[
$class])) {
470 return $this->_resources[
$class];
$_option $_optionId $class
◆ removeResourceType()
removeResourceType |
( |
|
$type | ) |
|
◆ setBasePath()
◆ setDefaultResourceType()
setDefaultResourceType |
( |
|
$type | ) |
|
◆ setNamespace()
setNamespace |
( |
|
$namespace | ) |
|
◆ setOptions()
setOptions |
( |
array |
$options | ) |
|
◆ setResourceTypes()
setResourceTypes |
( |
array |
$types | ) |
|
◆ $_basePath
◆ $_components
◆ $_defaultResourceType
◆ $_namespace
◆ $_resourceTypes
$_resourceTypes = array() |
|
protected |
The documentation for this class was generated from the following file:
- vendor/magento/zendframework1/library/Zend/Loader/Autoloader/Resource.php