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

Public Member Functions

 __construct ($baseDir)
 
 getFile ($class)
 
 addMap (array $map)
 
 load ($class)
 

Protected Attributes

 $_baseDir
 
 $_map = []
 

Detailed Description

Definition at line 10 of file ClassMap.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $baseDir)

Set base directory absolute path

Parameters
string$baseDir
Exceptions

Definition at line 36 of file ClassMap.php.

37  {
38  $this->_baseDir = realpath($baseDir);
39  if (!$this->_baseDir || !is_dir($this->_baseDir)) {
40  throw new \InvalidArgumentException("Specified path is not a valid directory: '{$baseDir}'");
41  }
42  }
$baseDir
Definition: autoload.php:9

Member Function Documentation

◆ addMap()

addMap ( array  $map)

Add classes files declaration to the map. New map will override existing values if such was defined before.

Parameters
array$map
Returns
$this

Definition at line 64 of file ClassMap.php.

65  {
66  $this->_map = array_merge($this->_map, $map);
67  return $this;
68  }

◆ getFile()

getFile (   $class)

Find an absolute path to a file to be included

Parameters
string$class
Returns
string|bool

Definition at line 50 of file ClassMap.php.

51  {
52  if (isset($this->_map[$class])) {
53  return $this->_baseDir . '/' . $this->_map[$class];
54  }
55  return false;
56  }
$_option $_optionId $class
Definition: date.phtml:13

◆ load()

load (   $class)

Resolve a class file and include it

Parameters
string$class
Returns
void

Definition at line 76 of file ClassMap.php.

77  {
78  $file = $this->getFile($class);
79  if (file_exists($file)) {
80  include $file;
81  }
82  }
$_option $_optionId $class
Definition: date.phtml:13

Field Documentation

◆ $_baseDir

$_baseDir
protected

Definition at line 17 of file ClassMap.php.

◆ $_map

$_map = []
protected

Definition at line 28 of file ClassMap.php.


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