Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Loader_StandardAutoloader Class Reference
Inheritance diagram for Zend_Loader_StandardAutoloader:
Zend_Loader_SplAutoloader

Public Member Functions

 __construct ($options=null)
 
 setOptions ($options)
 
 setFallbackAutoloader ($flag)
 
 isFallbackAutoloader ()
 
 registerNamespace ($namespace, $directory)
 
 registerNamespaces ($namespaces)
 
 registerPrefix ($prefix, $directory)
 
 registerPrefixes ($prefixes)
 
 autoload ($class)
 
 register ()
 
 handleError ($errno, $errstr)
 

Data Fields

const NS_SEPARATOR = '\\'
 
const PREFIX_SEPARATOR = '_'
 
const LOAD_NS = 'namespaces'
 
const LOAD_PREFIX = 'prefixes'
 
const ACT_AS_FALLBACK = 'fallback_autoloader'
 
const AUTOREGISTER_ZF = 'autoregister_zf'
 

Protected Member Functions

 transformClassNameToFilename ($class, $directory)
 
 loadClass ($class, $type)
 
 normalizeDirectory ($directory)
 

Protected Attributes

 $namespaces = array()
 
 $prefixes = array()
 
 $fallbackAutoloaderFlag = false
 
 $error
 

Detailed Description

Definition at line 35 of file StandardAutoloader.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Constructor

Parameters
null | array | Traversable$options
Returns
void

Implements Zend_Loader_SplAutoloader.

Definition at line 70 of file StandardAutoloader.php.

71  {
72  if (null !== $options) {
73  $this->setOptions($options);
74  }
75  }

Member Function Documentation

◆ autoload()

autoload (   $class)

Defined by Autoloadable; autoload a class

Parameters
string$class
Returns
false|string

Implements Zend_Loader_SplAutoloader.

Definition at line 226 of file StandardAutoloader.php.

227  {
228  $isFallback = $this->isFallbackAutoloader();
229  if (false !== strpos($class, self::NS_SEPARATOR)) {
230  if ($this->loadClass($class, self::LOAD_NS)) {
231  return $class;
232  } elseif ($isFallback) {
233  return $this->loadClass($class, self::ACT_AS_FALLBACK);
234  }
235  return false;
236  }
237  if (false !== strpos($class, self::PREFIX_SEPARATOR)) {
238  if ($this->loadClass($class, self::LOAD_PREFIX)) {
239  return $class;
240  } elseif ($isFallback) {
241  return $this->loadClass($class, self::ACT_AS_FALLBACK);
242  }
243  return false;
244  }
245  if ($isFallback) {
246  return $this->loadClass($class, self::ACT_AS_FALLBACK);
247  }
248  return false;
249  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$_option $_optionId $class
Definition: date.phtml:13

◆ handleError()

handleError (   $errno,
  $errstr 
)

Error handler

Used by loadClass during fallback autoloading in PHP versions prior to 5.3.0.

Parameters
mixed$errno
mixed$errstr
Returns
void

Definition at line 271 of file StandardAutoloader.php.

272  {
273  $this->error = true;
274  }

◆ isFallbackAutoloader()

isFallbackAutoloader ( )

Is this autoloader acting as a fallback autoloader?

Returns
bool

Definition at line 149 of file StandardAutoloader.php.

◆ loadClass()

loadClass (   $class,
  $type 
)
protected

Load a class, based on its type (namespaced or prefixed)

Parameters
string$class
string$type
Returns
void

Definition at line 306 of file StandardAutoloader.php.

307  {
308  if (!in_array($type, array(self::LOAD_NS, self::LOAD_PREFIX, self::ACT_AS_FALLBACK))) {
309  #require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
311  }
312 
313  // Fallback autoloading
314  if ($type === self::ACT_AS_FALLBACK) {
315  // create filename
316  $filename = $this->transformClassNameToFilename($class, '');
317  if (version_compare(PHP_VERSION, '5.3.2', '>=')) {
318  $resolvedName = stream_resolve_include_path($filename);
319  if ($resolvedName !== false) {
320  return include $resolvedName;
321  }
322  return false;
323  }
324  $this->error = false;
325  set_error_handler(array($this, 'handleError'), E_WARNING);
326  include $filename;
327  restore_error_handler();
328  if ($this->error) {
329  return false;
330  }
331  return class_exists($class, false);
332  }
333 
334  // Namespace and/or prefix autoloading
335  foreach ($this->$type as $leader => $path) {
336  if (0 === strpos($class, $leader)) {
337  // Trim off leader (namespace or prefix)
338  $trimmedClass = substr($class, strlen($leader));
339 
340  // create filename
341  $filename = $this->transformClassNameToFilename($trimmedClass, $path);
342  if (file_exists($filename)) {
343  return include $filename;
344  }
345  return false;
346  }
347  }
348  return false;
349  }
transformClassNameToFilename($class, $directory)
$type
Definition: item.phtml:13
$_option $_optionId $class
Definition: date.phtml:13

◆ normalizeDirectory()

normalizeDirectory (   $directory)
protected

Normalize the directory to include a trailing directory separator

Parameters
string$directory
Returns
string

Definition at line 357 of file StandardAutoloader.php.

358  {
359  $last = $directory[strlen($directory) - 1];
360  if (in_array($last, array('/', '\\'))) {
361  $directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
362  return $directory;
363  }
364  $directory .= DIRECTORY_SEPARATOR;
365  return $directory;
366  }

◆ register()

register ( )

Register the autoloader with spl_autoload

Returns
void

Implements Zend_Loader_SplAutoloader.

Definition at line 256 of file StandardAutoloader.php.

257  {
258  spl_autoload_register(array($this, 'autoload'));
259  }

◆ registerNamespace()

registerNamespace (   $namespace,
  $directory 
)

Register a namespace/directory pair

Parameters
string$namespace
string$directory
Returns
Zend_Loader_StandardAutoloader

Definition at line 161 of file StandardAutoloader.php.

162  {
163  $namespace = rtrim($namespace, self::NS_SEPARATOR). self::NS_SEPARATOR;
164  $this->namespaces[$namespace] = $this->normalizeDirectory($directory);
165  return $this;
166  }

◆ registerNamespaces()

registerNamespaces (   $namespaces)

Register many namespace/directory pairs at once

Parameters
array$namespaces
Returns
Zend_Loader_StandardAutoloader

Definition at line 174 of file StandardAutoloader.php.

175  {
176  if (!is_array($namespaces) && !$namespaces instanceof Traversable) {
177  #require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
178  throw new Zend_Loader_Exception_InvalidArgumentException('Namespace pairs must be either an array or Traversable');
179  }
180 
181  foreach ($namespaces as $namespace => $directory) {
182  $this->registerNamespace($namespace, $directory);
183  }
184  return $this;
185  }
registerNamespace($namespace, $directory)

◆ registerPrefix()

registerPrefix (   $prefix,
  $directory 
)

Register a prefix/directory pair

Parameters
string$prefix
string$directory
Returns
Zend_Loader_StandardAutoloader

Definition at line 194 of file StandardAutoloader.php.

195  {
196  $prefix = rtrim($prefix, self::PREFIX_SEPARATOR). self::PREFIX_SEPARATOR;
197  $this->prefixes[$prefix] = $this->normalizeDirectory($directory);
198  return $this;
199  }
$prefix
Definition: name.phtml:25

◆ registerPrefixes()

registerPrefixes (   $prefixes)

Register many namespace/directory pairs at once

Parameters
array$prefixes
Returns
Zend_Loader_StandardAutoloader

Definition at line 207 of file StandardAutoloader.php.

208  {
209  if (!is_array($prefixes) && !$prefixes instanceof Traversable) {
210  #require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
211  throw new Zend_Loader_Exception_InvalidArgumentException('Prefix pairs must be either an array or Traversable');
212  }
213 
214  foreach ($prefixes as $prefix => $directory) {
215  $this->registerPrefix($prefix, $directory);
216  }
217  return $this;
218  }
$prefix
Definition: name.phtml:25

◆ setFallbackAutoloader()

setFallbackAutoloader (   $flag)

Set flag indicating fallback autoloader status

Parameters
bool$flag
Returns
Zend_Loader_StandardAutoloader

Definition at line 138 of file StandardAutoloader.php.

139  {
140  $this->fallbackAutoloaderFlag = (bool) $flag;
141  return $this;
142  }

◆ setOptions()

setOptions (   $options)

Configure autoloader

Allows specifying both "namespace" and "prefix" pairs, using the following structure: array( 'namespaces' => array( 'Zend' => '/path/to/Zend/library', 'Doctrine' => '/path/to/Doctrine/library', ), 'prefixes' => array( 'Phly_' => '/path/to/Phly/library', ), 'fallback_autoloader' => true, )

Parameters
array | Traversable$options
Returns
Zend_Loader_StandardAutoloader

Implements Zend_Loader_SplAutoloader.

Definition at line 98 of file StandardAutoloader.php.

99  {
100  if (!is_array($options) && !($options instanceof Traversable)) {
101  #require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
102  throw new Zend_Loader_Exception_InvalidArgumentException('Options must be either an array or Traversable');
103  }
104 
105  foreach ($options as $type => $pairs) {
106  switch ($type) {
108  if ($pairs) {
109  $this->registerPrefix('Zend', dirname(dirname(__FILE__)));
110  }
111  break;
112  case self::LOAD_NS:
113  if (is_array($pairs) || $pairs instanceof Traversable) {
114  $this->registerNamespaces($pairs);
115  }
116  break;
117  case self::LOAD_PREFIX:
118  if (is_array($pairs) || $pairs instanceof Traversable) {
119  $this->registerPrefixes($pairs);
120  }
121  break;
123  $this->setFallbackAutoloader($pairs);
124  break;
125  default:
126  // ignore
127  }
128  }
129  return $this;
130  }
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
Definition: bootstrap.php:7
$type
Definition: item.phtml:13

◆ transformClassNameToFilename()

transformClassNameToFilename (   $class,
  $directory 
)
protected

Transform the class name to a filename

Parameters
string$class
string$directory
Returns
string

Definition at line 283 of file StandardAutoloader.php.

284  {
285  // $class may contain a namespace portion, in which case we need
286  // to preserve any underscores in that portion.
287  $matches = array();
288  preg_match('/(?P<namespace>.+\\\)?(?P<class>[^\\\]+$)/', $class, $matches);
289 
290  $class = (isset($matches['class'])) ? $matches['class'] : '';
291  $namespace = (isset($matches['namespace'])) ? $matches['namespace'] : '';
292 
293  return $directory
294  . str_replace(self::NS_SEPARATOR, '/', $namespace)
295  . str_replace(self::PREFIX_SEPARATOR, '/', $class)
296  . '.php';
297  }
$_option $_optionId $class
Definition: date.phtml:13

Field Documentation

◆ $error

$error
protected

Definition at line 62 of file StandardAutoloader.php.

◆ $fallbackAutoloaderFlag

$fallbackAutoloaderFlag = false
protected

Definition at line 57 of file StandardAutoloader.php.

◆ $namespaces

$namespaces = array()
protected

Definition at line 47 of file StandardAutoloader.php.

◆ $prefixes

$prefixes = array()
protected

Definition at line 52 of file StandardAutoloader.php.

◆ ACT_AS_FALLBACK

const ACT_AS_FALLBACK = 'fallback_autoloader'

Definition at line 41 of file StandardAutoloader.php.

◆ AUTOREGISTER_ZF

const AUTOREGISTER_ZF = 'autoregister_zf'

Definition at line 42 of file StandardAutoloader.php.

◆ LOAD_NS

const LOAD_NS = 'namespaces'

Definition at line 39 of file StandardAutoloader.php.

◆ LOAD_PREFIX

const LOAD_PREFIX = 'prefixes'

Definition at line 40 of file StandardAutoloader.php.

◆ NS_SEPARATOR

const NS_SEPARATOR = '\\'

Definition at line 37 of file StandardAutoloader.php.

◆ PREFIX_SEPARATOR

const PREFIX_SEPARATOR = '_'

Definition at line 38 of file StandardAutoloader.php.


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