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
Zend_Loader_ClassMapAutoloader Class Reference
Inheritance diagram for Zend_Loader_ClassMapAutoloader:
Zend_Loader_SplAutoloader

Public Member Functions

 __construct ($options=null)
 
 setOptions ($options)
 
 registerAutoloadMap ($map)
 
 registerAutoloadMaps ($locations)
 
 getAutoloadMap ()
 
 autoload ($class)
 
 register ()
 

Static Public Member Functions

static realPharPath ($path)
 
static concatPharParts ($part)
 
static resolvePharParentPath ($value, $key, &$parts)
 

Protected Member Functions

 loadMapFromFile ($location)
 

Protected Attributes

 $mapsLoaded = array()
 
 $map = array()
 

Detailed Description

Definition at line 33 of file ClassMapAutoloader.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Constructor

Create a new instance, and optionally configure the autoloader.

Parameters
null | array | Traversable$options
Returns
void

Implements Zend_Loader_SplAutoloader.

Definition at line 55 of file ClassMapAutoloader.php.

56  {
57  if (null !== $options) {
58  $this->setOptions($options);
59  }
60  }

Member Function Documentation

◆ autoload()

autoload (   $class)

Defined by Autoloadable

Parameters
string$class
Returns
void

Implements Zend_Loader_SplAutoloader.

Definition at line 145 of file ClassMapAutoloader.php.

146  {
147  if (isset($this->map[$class])) {
148  #require_once $this->map[$class];
149  }
150  }
$_option $_optionId $class
Definition: date.phtml:13

◆ concatPharParts()

static concatPharParts (   $part)
static

Helper callback for filtering phar paths

Parameters
string$part
Returns
bool

Definition at line 227 of file ClassMapAutoloader.php.

228  {
229  return ($part !== '' && $part !== '.');
230  }

◆ getAutoloadMap()

getAutoloadMap ( )

Retrieve current autoload map

Returns
array

Definition at line 134 of file ClassMapAutoloader.php.

135  {
136  return $this->map;
137  }

◆ loadMapFromFile()

loadMapFromFile (   $location)
protected

Load a map from a file

If the map has been previously loaded, returns the current instance; otherwise, returns whatever was returned by calling include() on the location.

Parameters
string$location
Returns
Zend_Loader_ClassMapAutoloader|mixed
Exceptions
Zend_Loader_Exception_InvalidArgumentExceptionfor nonexistent locations

Definition at line 177 of file ClassMapAutoloader.php.

178  {
179  if (!file_exists($location)) {
180  #require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
181  throw new Zend_Loader_Exception_InvalidArgumentException('Map file provided does not exist');
182  }
183 
184  if (!$path = self::realPharPath($location)) {
185  $path = realpath($location);
186  }
187 
188  if (in_array($path, $this->mapsLoaded)) {
189  // Already loaded this map
190  return $this;
191  }
192 
193  $map = include $path;
194 
195  return $map;
196  }

◆ realPharPath()

static realPharPath (   $path)
static

Resolve the real_path() to a file within a phar.

See also
https://bugs.php.net/bug.php?id=52769
Parameters
string$path
Returns
string

Definition at line 205 of file ClassMapAutoloader.php.

206  {
207  if (strpos($path, 'phar:///') !== 0) {
208  return;
209  }
210 
211  $parts = explode('/', str_replace(array('/','\\'), '/', substr($path, 8)));
212  $parts = array_values(array_filter($parts, array(__CLASS__, 'concatPharParts')));
213 
214  array_walk($parts, array(__CLASS__, 'resolvePharParentPath'), $parts);
215 
216  if (file_exists($realPath = 'phar:///' . implode('/', $parts))) {
217  return $realPath;
218  }
219  }

◆ register()

register ( )

Register the autoloader with spl_autoload registry

Returns
void

Implements Zend_Loader_SplAutoloader.

Definition at line 157 of file ClassMapAutoloader.php.

158  {
159  if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
160  spl_autoload_register(array($this, 'autoload'), true, true);
161  } else {
162  spl_autoload_register(array($this, 'autoload'), true);
163  }
164  }

◆ registerAutoloadMap()

registerAutoloadMap (   $map)

Register an autoload map

An autoload map may be either an associative array, or a file returning an associative array.

An autoload map should be an associative array containing classname/file pairs.

Parameters
string | array$location
Returns
Zend_Loader_ClassMapAutoloader

Definition at line 88 of file ClassMapAutoloader.php.

89  {
90  if (is_string($map)) {
91  $location = $map;
92  if ($this === ($map = $this->loadMapFromFile($location))) {
93  return $this;
94  }
95  }
96 
97  if (!is_array($map)) {
98  #require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
99  throw new Zend_Loader_Exception_InvalidArgumentException('Map file provided does not return a map');
100  }
101 
102  $this->map = array_merge($this->map, $map);
103 
104  if (isset($location)) {
105  $this->mapsLoaded[] = $location;
106  }
107 
108  return $this;
109  }

◆ registerAutoloadMaps()

registerAutoloadMaps (   $locations)

Register many autoload maps at once

Parameters
array$locations
Returns
Zend_Loader_ClassMapAutoloader

Definition at line 117 of file ClassMapAutoloader.php.

118  {
119  if (!is_array($locations) && !($locations instanceof Traversable)) {
120  #require_once dirname(__FILE__) . '/Exception/InvalidArgumentException.php';
121  throw new Zend_Loader_Exception_InvalidArgumentException('Map list must be an array or implement Traversable');
122  }
123  foreach ($locations as $location) {
124  $this->registerAutoloadMap($location);
125  }
126  return $this;
127  }

◆ resolvePharParentPath()

static resolvePharParentPath (   $value,
  $key,
$parts 
)
static

Helper callback to resolve a parent path in a Phar archive

Parameters
string$value
int$key
array$parts
Returns
void

Definition at line 240 of file ClassMapAutoloader.php.

241  {
242  if ($value !== '...') {
243  return;
244  }
245  unset($parts[$key], $parts[$key-1]);
246  $parts = array_values($parts);
247  }
$value
Definition: gender.phtml:16

◆ setOptions()

setOptions (   $options)

Configure the autoloader

Proxies to registerAutoloadMaps().

Parameters
array | Traversable$options
Returns
Zend_Loader_ClassMapAutoloader

Implements Zend_Loader_SplAutoloader.

Definition at line 70 of file ClassMapAutoloader.php.

71  {
73  return $this;
74  }

Field Documentation

◆ $map

$map = array()
protected

Definition at line 45 of file ClassMapAutoloader.php.

◆ $mapsLoaded

$mapsLoaded = array()
protected

Definition at line 39 of file ClassMapAutoloader.php.


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