|
|
@ -42,75 +42,30 @@ namespace Composer\Autoload; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class ClassLoader |
|
|
|
class ClassLoader |
|
|
|
{ |
|
|
|
{ |
|
|
|
/** @var ?string */ |
|
|
|
|
|
|
|
private $vendorDir; |
|
|
|
private $vendorDir; |
|
|
|
|
|
|
|
|
|
|
|
// PSR-4 |
|
|
|
// PSR-4 |
|
|
|
/** |
|
|
|
|
|
|
|
* @var array[] |
|
|
|
|
|
|
|
* @psalm-var array<string, array<string, int>> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private $prefixLengthsPsr4 = array(); |
|
|
|
private $prefixLengthsPsr4 = array(); |
|
|
|
/** |
|
|
|
|
|
|
|
* @var array[] |
|
|
|
|
|
|
|
* @psalm-var array<string, array<int, string>> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private $prefixDirsPsr4 = array(); |
|
|
|
private $prefixDirsPsr4 = array(); |
|
|
|
/** |
|
|
|
|
|
|
|
* @var array[] |
|
|
|
|
|
|
|
* @psalm-var array<string, string> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private $fallbackDirsPsr4 = array(); |
|
|
|
private $fallbackDirsPsr4 = array(); |
|
|
|
|
|
|
|
|
|
|
|
// PSR-0 |
|
|
|
// PSR-0 |
|
|
|
/** |
|
|
|
|
|
|
|
* @var array[] |
|
|
|
|
|
|
|
* @psalm-var array<string, array<string, string[]>> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private $prefixesPsr0 = array(); |
|
|
|
private $prefixesPsr0 = array(); |
|
|
|
/** |
|
|
|
|
|
|
|
* @var array[] |
|
|
|
|
|
|
|
* @psalm-var array<string, string> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private $fallbackDirsPsr0 = array(); |
|
|
|
private $fallbackDirsPsr0 = array(); |
|
|
|
|
|
|
|
|
|
|
|
/** @var bool */ |
|
|
|
|
|
|
|
private $useIncludePath = false; |
|
|
|
private $useIncludePath = false; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @var string[] |
|
|
|
|
|
|
|
* @psalm-var array<string, string> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private $classMap = array(); |
|
|
|
private $classMap = array(); |
|
|
|
|
|
|
|
|
|
|
|
/** @var bool */ |
|
|
|
|
|
|
|
private $classMapAuthoritative = false; |
|
|
|
private $classMapAuthoritative = false; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @var bool[] |
|
|
|
|
|
|
|
* @psalm-var array<string, bool> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private $missingClasses = array(); |
|
|
|
private $missingClasses = array(); |
|
|
|
|
|
|
|
|
|
|
|
/** @var ?string */ |
|
|
|
|
|
|
|
private $apcuPrefix; |
|
|
|
private $apcuPrefix; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @var self[] |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static $registeredLoaders = array(); |
|
|
|
private static $registeredLoaders = array(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @param ?string $vendorDir |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function __construct($vendorDir = null) |
|
|
|
public function __construct($vendorDir = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->vendorDir = $vendorDir; |
|
|
|
$this->vendorDir = $vendorDir; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return string[] |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getPrefixes() |
|
|
|
public function getPrefixes() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!empty($this->prefixesPsr0)) { |
|
|
|
if (!empty($this->prefixesPsr0)) { |
|
|
@ -120,47 +75,28 @@ class ClassLoader |
|
|
|
return array(); |
|
|
|
return array(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return array[] |
|
|
|
|
|
|
|
* @psalm-return array<string, array<int, string>> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getPrefixesPsr4() |
|
|
|
public function getPrefixesPsr4() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->prefixDirsPsr4; |
|
|
|
return $this->prefixDirsPsr4; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return array[] |
|
|
|
|
|
|
|
* @psalm-return array<string, string> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getFallbackDirs() |
|
|
|
public function getFallbackDirs() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->fallbackDirsPsr0; |
|
|
|
return $this->fallbackDirsPsr0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return array[] |
|
|
|
|
|
|
|
* @psalm-return array<string, string> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getFallbackDirsPsr4() |
|
|
|
public function getFallbackDirsPsr4() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->fallbackDirsPsr4; |
|
|
|
return $this->fallbackDirsPsr4; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @return string[] Array of classname => path |
|
|
|
|
|
|
|
* @psalm-return array<string, string> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getClassMap() |
|
|
|
public function getClassMap() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->classMap; |
|
|
|
return $this->classMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param string[] $classMap Class to filename map |
|
|
|
* @param array $classMap Class to filename map |
|
|
|
* @psalm-param array<string, string> $classMap |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function addClassMap(array $classMap) |
|
|
|
public function addClassMap(array $classMap) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -175,11 +111,9 @@ class ClassLoader |
|
|
|
* Registers a set of PSR-0 directories for a given prefix, either |
|
|
|
* Registers a set of PSR-0 directories for a given prefix, either |
|
|
|
* appending or prepending to the ones previously set for this prefix. |
|
|
|
* appending or prepending to the ones previously set for this prefix. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param string $prefix The prefix |
|
|
|
* @param string $prefix The prefix |
|
|
|
* @param string[]|string $paths The PSR-0 root directories |
|
|
|
* @param array|string $paths The PSR-0 root directories |
|
|
|
* @param bool $prepend Whether to prepend the directories |
|
|
|
* @param bool $prepend Whether to prepend the directories |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function add($prefix, $paths, $prepend = false) |
|
|
|
public function add($prefix, $paths, $prepend = false) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -222,13 +156,11 @@ class ClassLoader |
|
|
|
* Registers a set of PSR-4 directories for a given namespace, either |
|
|
|
* Registers a set of PSR-4 directories for a given namespace, either |
|
|
|
* appending or prepending to the ones previously set for this namespace. |
|
|
|
* appending or prepending to the ones previously set for this namespace. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param string $prefix The prefix/namespace, with trailing '\\' |
|
|
|
* @param string $prefix The prefix/namespace, with trailing '\\' |
|
|
|
* @param string[]|string $paths The PSR-4 base directories |
|
|
|
* @param array|string $paths The PSR-4 base directories |
|
|
|
* @param bool $prepend Whether to prepend the directories |
|
|
|
* @param bool $prepend Whether to prepend the directories |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws \InvalidArgumentException |
|
|
|
* @throws \InvalidArgumentException |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function addPsr4($prefix, $paths, $prepend = false) |
|
|
|
public function addPsr4($prefix, $paths, $prepend = false) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -272,10 +204,8 @@ class ClassLoader |
|
|
|
* Registers a set of PSR-0 directories for a given prefix, |
|
|
|
* Registers a set of PSR-0 directories for a given prefix, |
|
|
|
* replacing any others previously set for this prefix. |
|
|
|
* replacing any others previously set for this prefix. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param string $prefix The prefix |
|
|
|
* @param string $prefix The prefix |
|
|
|
* @param string[]|string $paths The PSR-0 base directories |
|
|
|
* @param array|string $paths The PSR-0 base directories |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function set($prefix, $paths) |
|
|
|
public function set($prefix, $paths) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -290,12 +220,10 @@ class ClassLoader |
|
|
|
* Registers a set of PSR-4 directories for a given namespace, |
|
|
|
* Registers a set of PSR-4 directories for a given namespace, |
|
|
|
* replacing any others previously set for this namespace. |
|
|
|
* replacing any others previously set for this namespace. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param string $prefix The prefix/namespace, with trailing '\\' |
|
|
|
* @param string $prefix The prefix/namespace, with trailing '\\' |
|
|
|
* @param string[]|string $paths The PSR-4 base directories |
|
|
|
* @param array|string $paths The PSR-4 base directories |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws \InvalidArgumentException |
|
|
|
* @throws \InvalidArgumentException |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function setPsr4($prefix, $paths) |
|
|
|
public function setPsr4($prefix, $paths) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -315,8 +243,6 @@ class ClassLoader |
|
|
|
* Turns on searching the include path for class files. |
|
|
|
* Turns on searching the include path for class files. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param bool $useIncludePath |
|
|
|
* @param bool $useIncludePath |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function setUseIncludePath($useIncludePath) |
|
|
|
public function setUseIncludePath($useIncludePath) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -339,8 +265,6 @@ class ClassLoader |
|
|
|
* that have not been registered with the class map. |
|
|
|
* that have not been registered with the class map. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param bool $classMapAuthoritative |
|
|
|
* @param bool $classMapAuthoritative |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function setClassMapAuthoritative($classMapAuthoritative) |
|
|
|
public function setClassMapAuthoritative($classMapAuthoritative) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -361,8 +285,6 @@ class ClassLoader |
|
|
|
* APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
|
|
* APCu prefix to use to cache found/not-found classes, if the extension is enabled. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param string|null $apcuPrefix |
|
|
|
* @param string|null $apcuPrefix |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function setApcuPrefix($apcuPrefix) |
|
|
|
public function setApcuPrefix($apcuPrefix) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -383,8 +305,6 @@ class ClassLoader |
|
|
|
* Registers this instance as an autoloader. |
|
|
|
* Registers this instance as an autoloader. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param bool $prepend Whether to prepend the autoloader or not |
|
|
|
* @param bool $prepend Whether to prepend the autoloader or not |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function register($prepend = false) |
|
|
|
public function register($prepend = false) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -404,8 +324,6 @@ class ClassLoader |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unregisters this instance as an autoloader. |
|
|
|
* Unregisters this instance as an autoloader. |
|
|
|
* |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function unregister() |
|
|
|
public function unregister() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -420,7 +338,7 @@ class ClassLoader |
|
|
|
* Loads the given class or interface. |
|
|
|
* Loads the given class or interface. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param string $class The name of the class |
|
|
|
* @param string $class The name of the class |
|
|
|
* @return true|null True if loaded, null otherwise |
|
|
|
* @return bool|null True if loaded, null otherwise |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function loadClass($class) |
|
|
|
public function loadClass($class) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -429,8 +347,6 @@ class ClassLoader |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -485,11 +401,6 @@ class ClassLoader |
|
|
|
return self::$registeredLoaders; |
|
|
|
return self::$registeredLoaders; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @param string $class |
|
|
|
|
|
|
|
* @param string $ext |
|
|
|
|
|
|
|
* @return string|false |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private function findFileWithExtension($class, $ext) |
|
|
|
private function findFileWithExtension($class, $ext) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// PSR-4 lookup |
|
|
|
// PSR-4 lookup |
|
|
@ -561,10 +472,6 @@ class ClassLoader |
|
|
|
* Scope isolated include. |
|
|
|
* Scope isolated include. |
|
|
|
* |
|
|
|
* |
|
|
|
* Prevents access to $this/self from included files. |
|
|
|
* Prevents access to $this/self from included files. |
|
|
|
* |
|
|
|
|
|
|
|
* @param string $file |
|
|
|
|
|
|
|
* @return void |
|
|
|
|
|
|
|
* @private |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function includeFile($file) |
|
|
|
function includeFile($file) |
|
|
|
{ |
|
|
|
{ |
|
|
|