Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions | Data Fields | Static Protected Member Functions | Static Protected Attributes
Zend_Loader_AutoloaderFactory Class Reference

Static Public Member Functions

static factory ($options=null)
 
static getRegisteredAutoloaders ()
 
static getRegisteredAutoloader ($class)
 
static unregisterAutoloaders ()
 
static unregisterAutoloader ($autoloaderClass)
 

Data Fields

const STANDARD_AUTOLOADER = 'Zend_Loader_StandardAutoloader'
 
const CLASS_MAP_AUTOLOADER = 'Zend_Loader_ClassMapAutoloader'
 

Static Protected Member Functions

static getStandardAutoloader ()
 

Static Protected Attributes

static $loaders = array()
 
static $standardAutoloader
 

Detailed Description

Definition at line 30 of file AutoloaderFactory.php.

Member Function Documentation

◆ factory()

array All autoloaders registered using the factory (   $options = null)
static

Factory for autoloaders

Options should be an array or Traversable object of the following structure: array( '<autoloader class="" name>="">' => $autoloaderOptions, )

The factory will then loop through and instantiate each autoloader with the specified options, and register each with the spl_autoloader.

You may retrieve the concrete autoloader instances later using getRegisteredAutoloaders().

Note that the class names must be resolvable on the include_path or via the Zend library, using PSR-0 rules (unless the class has already been loaded).

Parameters
array | Traversable$options(optional) options to use. Defaults to Zend_Loader_StandardAutoloader
Returns
void
Exceptions
Zend_Loader_Exception_InvalidArgumentExceptionfor invalid options
Zend_Loader_Exception_InvalidArgumentExceptionfor unloadable autoloader classes

Definition at line 71 of file AutoloaderFactory.php.

72  {
73  if (null === $options) {
74  if (!isset(self::$loaders[self::STANDARD_AUTOLOADER])) {
75  $autoloader = self::getStandardAutoloader();
76  $autoloader->register();
77  self::$loaders[self::STANDARD_AUTOLOADER] = $autoloader;
78  }
79 
80  // Return so we don't hit the next check's exception (we're done here anyway)
81  return;
82  }
83 
84  if (!is_array($options) && !($options instanceof Traversable)) {
85  #require_once 'Exception/InvalidArgumentException.php';
87  'Options provided must be an array or Traversable'
88  );
89  }
90 
91  foreach ($options as $class => $options) {
92  if (!isset(self::$loaders[$class])) {
93  // Check class map autoloader
94  if ($class == self::CLASS_MAP_AUTOLOADER) {
95  if (!class_exists(self::CLASS_MAP_AUTOLOADER)) {
96  // Extract the filename from the classname
97  $classMapLoader = substr(
98  strrchr(self::CLASS_MAP_AUTOLOADER, '_'), 1
99  );
100 
101  require_once dirname(__FILE__) . "/$classMapLoader.php";
102  }
103  }
104 
105  // Autoload with standard autoloader
106  $autoloader = self::getStandardAutoloader();
107  if (!class_exists($class) && !$autoloader->autoload($class)) {
108  #require_once 'Exception/InvalidArgumentException.php';
110  'Autoloader class "%s" not loaded',
111  $class
112  ));
113  }
114 
115  // unfortunately is_subclass_of is broken on some 5.3 versions
116  // additionally instanceof is also broken for this use case
117  if (version_compare(PHP_VERSION, '5.3.7', '>=')) {
118  if (!is_subclass_of($class, 'Zend_Loader_SplAutoloader')) {
119  #require_once 'Exception/InvalidArgumentException.php';
121  'Autoloader class %s must implement Zend\\Loader\\SplAutoloader',
122  $class
123  ));
124  }
125  }
126 
127  if ($class === self::STANDARD_AUTOLOADER) {
128  $autoloader->setOptions($options);
129  } else {
130  $autoloader = new $class($options);
131  }
132  $autoloader->register();
133  self::$loaders[$class] = $autoloader;
134  } else {
135  self::$loaders[$class]->setOptions($options);
136  }
137  }
138  }
is_subclass_of($obj, $className)
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
Definition: bootstrap.php:7
$_option $_optionId $class
Definition: date.phtml:13

◆ getRegisteredAutoloader()

static getRegisteredAutoloader (   $class)
static

Retrieves an autoloader by class name

Parameters
string$class
Returns
Zend_Loader_SplAutoloader
Exceptions
Zend_Loader_Exception_InvalidArgumentExceptionfor non-registered class

Definition at line 159 of file AutoloaderFactory.php.

160  {
161  if (!isset(self::$loaders[$class])) {
162  #require_once 'Exception/InvalidArgumentException.php';
163  throw new Zend_Loader_Exception_InvalidArgumentException(sprintf('Autoloader class "%s" not loaded', $class));
164  }
165  return self::$loaders[$class];
166  }
$_option $_optionId $class
Definition: date.phtml:13

◆ getRegisteredAutoloaders()

static getRegisteredAutoloaders ( )
static

Get an list of all autoloaders registered with the factory

Returns an array of autoloader instances.

Returns
array

Definition at line 147 of file AutoloaderFactory.php.

148  {
149  return self::$loaders;
150  }

◆ getStandardAutoloader()

static getStandardAutoloader ( )
staticprotected

Get an instance of the standard autoloader

Used to attempt to resolve autoloader classes, using the StandardAutoloader. The instance is marked as a fallback autoloader, to allow resolving autoloaders not under the "Zend" or "Zend" namespaces.

Returns
Zend_Loader_SplAutoloader

Definition at line 209 of file AutoloaderFactory.php.

210  {
211  if (null !== self::$standardAutoloader) {
213  }
214 
215  // Extract the filename from the classname
216  $stdAutoloader = substr(strrchr(self::STANDARD_AUTOLOADER, '_'), 1);
217 
218  if (!class_exists(self::STANDARD_AUTOLOADER)) {
219  #require_once dirname(__FILE__) . "/$stdAutoloader.php";
220  }
222  self::$standardAutoloader = $loader;
224  }
$loader
Definition: autoload.php:8

◆ unregisterAutoloader()

static unregisterAutoloader (   $autoloaderClass)
static

Unregister a single autoloader by class name

Parameters
string$autoloaderClass
Returns
bool

Definition at line 188 of file AutoloaderFactory.php.

189  {
190  if (!isset(self::$loaders[$autoloaderClass])) {
191  return false;
192  }
193 
194  $autoloader = self::$loaders[$autoloaderClass];
195  spl_autoload_unregister(array($autoloader, 'autoload'));
196  unset(self::$loaders[$autoloaderClass]);
197  return true;
198  }

◆ unregisterAutoloaders()

static unregisterAutoloaders ( )
static

Unregisters all autoloaders that have been registered via the factory. This will NOT unregister autoloaders registered outside of the fctory.

Returns
void

Definition at line 174 of file AutoloaderFactory.php.

175  {
176  foreach (self::getRegisteredAutoloaders() as $class => $autoloader) {
177  spl_autoload_unregister(array($autoloader, 'autoload'));
178  unset(self::$loaders[$class]);
179  }
180  }
$_option $_optionId $class
Definition: date.phtml:13

Field Documentation

◆ $loaders

$loaders = array()
staticprotected

Definition at line 38 of file AutoloaderFactory.php.

◆ $standardAutoloader

$standardAutoloader
staticprotected

Definition at line 44 of file AutoloaderFactory.php.

◆ CLASS_MAP_AUTOLOADER

const CLASS_MAP_AUTOLOADER = 'Zend_Loader_ClassMapAutoloader'

Definition at line 33 of file AutoloaderFactory.php.

◆ STANDARD_AUTOLOADER

const STANDARD_AUTOLOADER = 'Zend_Loader_StandardAutoloader'

Definition at line 32 of file AutoloaderFactory.php.


The documentation for this class was generated from the following file: