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

Public Member Functions

 setDefaultAutoloader ($callback)
 
 getDefaultAutoloader ()
 
 setAutoloaders (array $autoloaders)
 
 getAutoloaders ()
 
 getNamespaceAutoloaders ($namespace)
 
 registerNamespace ($namespace)
 
 unregisterNamespace ($namespace)
 
 getRegisteredNamespaces ()
 
 setZfPath ($spec, $version='latest')
 
 getZfPath ()
 
 suppressNotFoundWarnings ($flag=null)
 
 setFallbackAutoloader ($flag)
 
 isFallbackAutoloader ()
 
 getClassAutoloaders ($class)
 
 unshiftAutoloader ($callback, $namespace='')
 
 pushAutoloader ($callback, $namespace='')
 
 removeAutoloader ($callback, $namespace=null)
 

Static Public Member Functions

static getInstance ()
 
static resetInstance ()
 
static autoload ($class)
 

Protected Member Functions

 __construct ()
 
 _autoload ($class)
 
 _setNamespaceAutoloaders (array $autoloaders, $namespace='')
 
 _getVersionPath ($path, $version)
 
 _getVersionType ($version)
 
 _getAvailableVersions ($path, $version)
 

Protected Attributes

 $_autoloaders = array()
 
 $_defaultAutoloader = array('Zend_Loader', 'loadClass')
 
 $_fallbackAutoloader = false
 
 $_internalAutoloader
 
 $_namespaces
 
 $_namespaceAutoloaders = array()
 
 $_suppressNotFoundWarnings = false
 
 $_zfPath
 

Static Protected Attributes

static $_instance
 

Detailed Description

Definition at line 35 of file Autoloader.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )
protected

Constructor

Registers instance with spl_autoload stack

Returns
void

Definition at line 460 of file Autoloader.php.

461  {
462  spl_autoload_register(array(__CLASS__, 'autoload'));
463  $this->_internalAutoloader = array($this, '_autoload');
464  }

Member Function Documentation

◆ _autoload()

_autoload (   $class)
protected

Internal autoloader implementation

Parameters
string$class
Returns
bool

Definition at line 472 of file Autoloader.php.

473  {
474  $callback = $this->getDefaultAutoloader();
475  try {
476  if ($this->suppressNotFoundWarnings()) {
477  @call_user_func($callback, $class);
478  } else {
479  call_user_func($callback, $class);
480  }
481  return $class;
482  } catch (Zend_Exception $e) {
483  return false;
484  }
485  }
suppressNotFoundWarnings($flag=null)
Definition: Autoloader.php:286
$_option $_optionId $class
Definition: date.phtml:13

◆ _getAvailableVersions()

_getAvailableVersions (   $path,
  $version 
)
protected

Get available versions for the version type requested

Parameters
string$path
string$version
Returns
array

Definition at line 559 of file Autoloader.php.

560  {
561  if (!is_dir($path)) {
562  throw new Zend_Loader_Exception('Invalid ZF path provided');
563  }
564 
565  $path = rtrim($path, '/');
566  $path = rtrim($path, '\\');
567  $versionLen = strlen($version);
568  $versions = array();
569  $dirs = glob("$path/*", GLOB_ONLYDIR);
570  foreach ((array) $dirs as $dir) {
571  $dirName = substr($dir, strlen($path) + 1);
572  if (!preg_match('/^(?:ZendFramework-)?(\d+\.\d+\.\d+((a|b|pl|pr|p|rc)\d+)?)(?:-minimal)?$/i', $dirName, $matches)) {
573  continue;
574  }
575 
576  $matchedVersion = $matches[1];
577 
578  if (('latest' == $version)
579  || ((strlen($matchedVersion) >= $versionLen)
580  && (0 === strpos($matchedVersion, $version)))
581  ) {
582  $versions[$matchedVersion] = $dir . '/library';
583  }
584  }
585 
586  uksort($versions, 'version_compare');
587  return $versions;
588  }

◆ _getVersionPath()

_getVersionPath (   $path,
  $version 
)
protected

Retrieve the filesystem path for the requested ZF version

Parameters
string$path
string$version
Returns
void

Definition at line 508 of file Autoloader.php.

509  {
510  $type = $this->_getVersionType($version);
511 
512  if ($type == 'latest') {
513  $version = 'latest';
514  }
515 
516  $availableVersions = $this->_getAvailableVersions($path, $version);
517  if (empty($availableVersions)) {
518  throw new Zend_Loader_Exception('No valid ZF installations discovered');
519  }
520 
521  $matchedVersion = array_pop($availableVersions);
522  return $matchedVersion;
523  }
$type
Definition: item.phtml:13
_getAvailableVersions($path, $version)
Definition: Autoloader.php:559

◆ _getVersionType()

_getVersionType (   $version)
protected

Retrieve the ZF version type

Parameters
string$version
Returns
string "latest", "major", "minor", or "specific"
Exceptions
Zend_Loader_Exceptionif version string contains too many dots

Definition at line 532 of file Autoloader.php.

533  {
534  if (strtolower($version) == 'latest') {
535  return 'latest';
536  }
537 
538  $parts = explode('.', $version);
539  $count = count($parts);
540  if (1 == $count) {
541  return 'major';
542  }
543  if (2 == $count) {
544  return 'minor';
545  }
546  if (3 < $count) {
547  throw new Zend_Loader_Exception('Invalid version string provided');
548  }
549  return 'specific';
550  }
$count
Definition: recent.phtml:13

◆ _setNamespaceAutoloaders()

_setNamespaceAutoloaders ( array  $autoloaders,
  $namespace = '' 
)
protected

Set autoloaders for a specific namespace

Parameters
array$autoloaders
string$namespace
Returns
Zend_Loader_Autoloader

Definition at line 494 of file Autoloader.php.

495  {
496  $namespace = (string) $namespace;
497  $this->_namespaceAutoloaders[$namespace] = $autoloaders;
498  return $this;
499  }

◆ autoload()

static autoload (   $class)
static

Autoload a class

Parameters
string$class
Returns
bool

Definition at line 114 of file Autoloader.php.

115  {
116  $self = self::getInstance();
117 
118  foreach ($self->getClassAutoloaders($class) as $autoloader) {
119  if ($autoloader instanceof Zend_Loader_Autoloader_Interface) {
120  if ($autoloader->autoload($class)) {
121  return true;
122  }
123  } elseif (is_array($autoloader)) {
124  if (call_user_func($autoloader, $class)) {
125  return true;
126  }
127  } elseif (is_string($autoloader) || is_callable($autoloader)) {
128  if ($autoloader($class)) {
129  return true;
130  }
131  }
132  }
133 
134  return false;
135  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$_option $_optionId $class
Definition: date.phtml:13

◆ getAutoloaders()

getAutoloaders ( )

Get attached autoloader implementations

Returns
array

Definition at line 180 of file Autoloader.php.

181  {
182  return $this->_autoloaders;
183  }

◆ getClassAutoloaders()

getClassAutoloaders (   $class)

Get autoloaders to use when matching class

Determines if the class matches a registered namespace, and, if so, returns only the autoloaders for that namespace. Otherwise, it returns all non-namespaced autoloaders.

Parameters
string$class
Returns
array Array of autoloaders to use

Definition at line 327 of file Autoloader.php.

328  {
329  $namespace = false;
330  $autoloaders = array();
331 
332  // Add concrete namespaced autoloaders
333  foreach (array_keys($this->_namespaceAutoloaders) as $ns) {
334  if ('' == $ns) {
335  continue;
336  }
337  if (0 === strpos($class, $ns)) {
338  if ((false === $namespace) || (strlen($ns) > strlen($namespace))) {
339  $namespace = $ns;
340  $autoloaders = $this->getNamespaceAutoloaders($ns);
341  }
342  }
343  }
344 
345  // Add internal namespaced autoloader
346  foreach ($this->getRegisteredNamespaces() as $ns) {
347  if (0 === strpos($class, $ns)) {
348  $namespace = $ns;
349  $autoloaders[] = $this->_internalAutoloader;
350  break;
351  }
352  }
353 
354  // Add non-namespaced autoloaders
355  $autoloadersNonNamespace = $this->getNamespaceAutoloaders('');
356  if (count($autoloadersNonNamespace)) {
357  foreach ($autoloadersNonNamespace as $ns) {
358  $autoloaders[] = $ns;
359  }
360  unset($autoloadersNonNamespace);
361  }
362 
363  // Add fallback autoloader
364  if (!$namespace && $this->isFallbackAutoloader()) {
365  $autoloaders[] = $this->_internalAutoloader;
366  }
367 
368  return $autoloaders;
369  }
getNamespaceAutoloaders($namespace)
Definition: Autoloader.php:191
$_option $_optionId $class
Definition: date.phtml:13

◆ getDefaultAutoloader()

getDefaultAutoloader ( )

Retrieve the default autoloader callback

Returns
string|array PHP Callback

Definition at line 158 of file Autoloader.php.

159  {
161  }

◆ getInstance()

static getInstance ( )
static

Retrieve singleton instance

Returns
Zend_Loader_Autoloader

Definition at line 90 of file Autoloader.php.

91  {
92  if (null === self::$_instance) {
93  self::$_instance = new self();
94  }
95  return self::$_instance;
96  }

◆ getNamespaceAutoloaders()

getNamespaceAutoloaders (   $namespace)

Return all autoloaders for a given namespace

Parameters
string$namespace
Returns
array

Definition at line 191 of file Autoloader.php.

192  {
193  $namespace = (string) $namespace;
194  if (!array_key_exists($namespace, $this->_namespaceAutoloaders)) {
195  return array();
196  }
197  return $this->_namespaceAutoloaders[$namespace];
198  }

◆ getRegisteredNamespaces()

getRegisteredNamespaces ( )

Get a list of registered autoload namespaces

Returns
array

Definition at line 249 of file Autoloader.php.

250  {
251  return array_keys($this->_namespaces);
252  }

◆ getZfPath()

getZfPath ( )

Definition at line 275 of file Autoloader.php.

276  {
277  return $this->_zfPath;
278  }

◆ isFallbackAutoloader()

isFallbackAutoloader ( )

Is this instance acting as a fallback autoloader?

Returns
bool

Definition at line 312 of file Autoloader.php.

313  {
315  }

◆ pushAutoloader()

pushAutoloader (   $callback,
  $namespace = '' 
)

Append an autoloader to the autoloader stack

Parameters
object | array | string$callbackPHP callback or Zend_Loader_Autoloader_Interface implementation
string | array$namespaceSpecific namespace(s) under which to register callback
Returns
Zend_Loader_Autoloader

Definition at line 401 of file Autoloader.php.

402  {
403  $autoloaders = $this->getAutoloaders();
404  array_push($autoloaders, $callback);
405  $this->setAutoloaders($autoloaders);
406 
407  $namespace = (array) $namespace;
408  foreach ($namespace as $ns) {
409  $autoloaders = $this->getNamespaceAutoloaders($ns);
410  array_push($autoloaders, $callback);
411  $this->_setNamespaceAutoloaders($autoloaders, $ns);
412  }
413 
414  return $this;
415  }
getNamespaceAutoloaders($namespace)
Definition: Autoloader.php:191
setAutoloaders(array $autoloaders)
Definition: Autoloader.php:169
_setNamespaceAutoloaders(array $autoloaders, $namespace='')
Definition: Autoloader.php:494

◆ registerNamespace()

registerNamespace (   $namespace)

Register a namespace to autoload

Parameters
string | array$namespace
Returns
Zend_Loader_Autoloader

Definition at line 206 of file Autoloader.php.

207  {
208  if (is_string($namespace)) {
209  $namespace = (array) $namespace;
210  } elseif (!is_array($namespace)) {
211  throw new Zend_Loader_Exception('Invalid namespace provided');
212  }
213 
214  foreach ($namespace as $ns) {
215  if (!isset($this->_namespaces[$ns])) {
216  $this->_namespaces[$ns] = true;
217  }
218  }
219  return $this;
220  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ removeAutoloader()

removeAutoloader (   $callback,
  $namespace = null 
)

Remove an autoloader from the autoloader stack

Parameters
object | array | string$callbackPHP callback or Zend_Loader_Autoloader_Interface implementation
null | string | array$namespaceSpecific namespace(s) from which to remove autoloader
Returns
Zend_Loader_Autoloader

Definition at line 424 of file Autoloader.php.

425  {
426  if (null === $namespace) {
427  $autoloaders = $this->getAutoloaders();
428  if (false !== ($index = array_search($callback, $autoloaders, true))) {
429  unset($autoloaders[$index]);
430  $this->setAutoloaders($autoloaders);
431  }
432 
433  foreach ($this->_namespaceAutoloaders as $ns => $autoloaders) {
434  if (false !== ($index = array_search($callback, $autoloaders, true))) {
435  unset($autoloaders[$index]);
436  $this->_setNamespaceAutoloaders($autoloaders, $ns);
437  }
438  }
439  } else {
440  $namespace = (array) $namespace;
441  foreach ($namespace as $ns) {
442  $autoloaders = $this->getNamespaceAutoloaders($ns);
443  if (false !== ($index = array_search($callback, $autoloaders, true))) {
444  unset($autoloaders[$index]);
445  $this->_setNamespaceAutoloaders($autoloaders, $ns);
446  }
447  }
448  }
449 
450  return $this;
451  }
getNamespaceAutoloaders($namespace)
Definition: Autoloader.php:191
setAutoloaders(array $autoloaders)
Definition: Autoloader.php:169
_setNamespaceAutoloaders(array $autoloaders, $namespace='')
Definition: Autoloader.php:494
$index
Definition: list.phtml:44

◆ resetInstance()

static resetInstance ( )
static

Reset the singleton instance

Returns
void

Definition at line 103 of file Autoloader.php.

104  {
105  self::$_instance = null;
106  }

◆ setAutoloaders()

setAutoloaders ( array  $autoloaders)

Set several autoloader callbacks at once

Parameters
array$autoloadersArray of PHP callbacks (or Zend_Loader_Autoloader_Interface implementations) to act as autoloaders
Returns
Zend_Loader_Autoloader

Definition at line 169 of file Autoloader.php.

170  {
171  $this->_autoloaders = $autoloaders;
172  return $this;
173  }

◆ setDefaultAutoloader()

setDefaultAutoloader (   $callback)

Set the default autoloader implementation

Parameters
string | array$callbackPHP callback
Returns
void

Definition at line 143 of file Autoloader.php.

144  {
145  if (!is_callable($callback)) {
146  throw new Zend_Loader_Exception('Invalid callback specified for default autoloader');
147  }
148 
149  $this->_defaultAutoloader = $callback;
150  return $this;
151  }

◆ setFallbackAutoloader()

setFallbackAutoloader (   $flag)

Indicate whether or not this autoloader should be a fallback autoloader

Parameters
bool$flag
Returns
Zend_Loader_Autoloader

Definition at line 301 of file Autoloader.php.

302  {
303  $this->_fallbackAutoloader = (bool) $flag;
304  return $this;
305  }

◆ setZfPath()

setZfPath (   $spec,
  $version = 'latest' 
)

Definition at line 254 of file Autoloader.php.

255  {
256  $path = $spec;
257  if (is_array($spec)) {
258  if (!isset($spec['path'])) {
259  throw new Zend_Loader_Exception('No path specified for ZF');
260  }
261  $path = $spec['path'];
262  if (isset($spec['version'])) {
263  $version = $spec['version'];
264  }
265  }
266 
267  $this->_zfPath = $this->_getVersionPath($path, $version);
268  set_include_path(implode(PATH_SEPARATOR, array(
269  $this->_zfPath,
270  get_include_path(),
271  )));
272  return $this;
273  }
_getVersionPath($path, $version)
Definition: Autoloader.php:508

◆ suppressNotFoundWarnings()

suppressNotFoundWarnings (   $flag = null)

Get or set the value of the "suppress not found warnings" flag

Parameters
null | bool$flag
Returns
bool|Zend_Loader_Autoloader Returns boolean if no argument is passed, object instance otherwise

Definition at line 286 of file Autoloader.php.

287  {
288  if (null === $flag) {
290  }
291  $this->_suppressNotFoundWarnings = (bool) $flag;
292  return $this;
293  }

◆ unregisterNamespace()

unregisterNamespace (   $namespace)

Unload a registered autoload namespace

Parameters
string | array$namespace
Returns
Zend_Loader_Autoloader

Definition at line 228 of file Autoloader.php.

229  {
230  if (is_string($namespace)) {
231  $namespace = (array) $namespace;
232  } elseif (!is_array($namespace)) {
233  throw new Zend_Loader_Exception('Invalid namespace provided');
234  }
235 
236  foreach ($namespace as $ns) {
237  if (isset($this->_namespaces[$ns])) {
238  unset($this->_namespaces[$ns]);
239  }
240  }
241  return $this;
242  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ unshiftAutoloader()

unshiftAutoloader (   $callback,
  $namespace = '' 
)

Add an autoloader to the beginning of the stack

Parameters
object | array | string$callbackPHP callback or Zend_Loader_Autoloader_Interface implementation
string | array$namespaceSpecific namespace(s) under which to register callback
Returns
Zend_Loader_Autoloader

Definition at line 378 of file Autoloader.php.

379  {
380  $autoloaders = $this->getAutoloaders();
381  array_unshift($autoloaders, $callback);
382  $this->setAutoloaders($autoloaders);
383 
384  $namespace = (array) $namespace;
385  foreach ($namespace as $ns) {
386  $autoloaders = $this->getNamespaceAutoloaders($ns);
387  array_unshift($autoloaders, $callback);
388  $this->_setNamespaceAutoloaders($autoloaders, $ns);
389  }
390 
391  return $this;
392  }
getNamespaceAutoloaders($namespace)
Definition: Autoloader.php:191
setAutoloaders(array $autoloaders)
Definition: Autoloader.php:169
_setNamespaceAutoloaders(array $autoloaders, $namespace='')
Definition: Autoloader.php:494

Field Documentation

◆ $_autoloaders

$_autoloaders = array()
protected

Definition at line 45 of file Autoloader.php.

◆ $_defaultAutoloader

$_defaultAutoloader = array('Zend_Loader', 'loadClass')
protected

Definition at line 50 of file Autoloader.php.

◆ $_fallbackAutoloader

$_fallbackAutoloader = false
protected

Definition at line 55 of file Autoloader.php.

◆ $_instance

$_instance
staticprotected

Definition at line 40 of file Autoloader.php.

◆ $_internalAutoloader

$_internalAutoloader
protected

Definition at line 60 of file Autoloader.php.

◆ $_namespaceAutoloaders

$_namespaceAutoloaders = array()
protected

Definition at line 73 of file Autoloader.php.

◆ $_namespaces

$_namespaces
protected
Initial value:
= array(
'Zend_' => true,
'ZendX_' => true,
)

Definition at line 65 of file Autoloader.php.

◆ $_suppressNotFoundWarnings

$_suppressNotFoundWarnings = false
protected

Definition at line 78 of file Autoloader.php.

◆ $_zfPath

$_zfPath
protected

Definition at line 83 of file Autoloader.php.


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