Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/duplicat.../vendor/composer
File: ClassLoader.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of Composer.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Nils Adermann <naderman@naderman.de>
[5] Fix | Delete
* Jordi Boggiano <j.boggiano@seld.be>
[6] Fix | Delete
*
[7] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[8] Fix | Delete
* file that was distributed with this source code.
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace Composer\Autoload;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
[15] Fix | Delete
*
[16] Fix | Delete
* $loader = new \Composer\Autoload\ClassLoader();
[17] Fix | Delete
*
[18] Fix | Delete
* // register classes with namespaces
[19] Fix | Delete
* $loader->add('Symfony\Component', __DIR__.'/component');
[20] Fix | Delete
* $loader->add('Symfony', __DIR__.'/framework');
[21] Fix | Delete
*
[22] Fix | Delete
* // activate the autoloader
[23] Fix | Delete
* $loader->register();
[24] Fix | Delete
*
[25] Fix | Delete
* // to enable searching the include path (eg. for PEAR packages)
[26] Fix | Delete
* $loader->setUseIncludePath(true);
[27] Fix | Delete
*
[28] Fix | Delete
* In this example, if you try to use a class in the Symfony\Component
[29] Fix | Delete
* namespace or one of its children (Symfony\Component\Console for instance),
[30] Fix | Delete
* the autoloader will first look for the class under the component/
[31] Fix | Delete
* directory, and it will then fallback to the framework/ directory if not
[32] Fix | Delete
* found before giving up.
[33] Fix | Delete
*
[34] Fix | Delete
* This class is loosely based on the Symfony UniversalClassLoader.
[35] Fix | Delete
*
[36] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[37] Fix | Delete
* @author Jordi Boggiano <j.boggiano@seld.be>
[38] Fix | Delete
* @see http://www.php-fig.org/psr/psr-0/
[39] Fix | Delete
* @see http://www.php-fig.org/psr/psr-4/
[40] Fix | Delete
*/
[41] Fix | Delete
class ClassLoader
[42] Fix | Delete
{
[43] Fix | Delete
// PSR-4
[44] Fix | Delete
private $prefixLengthsPsr4 = array();
[45] Fix | Delete
private $prefixDirsPsr4 = array();
[46] Fix | Delete
private $fallbackDirsPsr4 = array();
[47] Fix | Delete
[48] Fix | Delete
// PSR-0
[49] Fix | Delete
private $prefixesPsr0 = array();
[50] Fix | Delete
private $fallbackDirsPsr0 = array();
[51] Fix | Delete
[52] Fix | Delete
private $useIncludePath = false;
[53] Fix | Delete
private $classMap = array();
[54] Fix | Delete
private $classMapAuthoritative = false;
[55] Fix | Delete
private $missingClasses = array();
[56] Fix | Delete
private $apcuPrefix;
[57] Fix | Delete
[58] Fix | Delete
public function getPrefixes()
[59] Fix | Delete
{
[60] Fix | Delete
if (!empty($this->prefixesPsr0)) {
[61] Fix | Delete
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
return array();
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
public function getPrefixesPsr4()
[68] Fix | Delete
{
[69] Fix | Delete
return $this->prefixDirsPsr4;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
public function getFallbackDirs()
[73] Fix | Delete
{
[74] Fix | Delete
return $this->fallbackDirsPsr0;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
public function getFallbackDirsPsr4()
[78] Fix | Delete
{
[79] Fix | Delete
return $this->fallbackDirsPsr4;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
public function getClassMap()
[83] Fix | Delete
{
[84] Fix | Delete
return $this->classMap;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* @param array $classMap Class to filename map
[89] Fix | Delete
*/
[90] Fix | Delete
public function addClassMap(array $classMap)
[91] Fix | Delete
{
[92] Fix | Delete
if ($this->classMap) {
[93] Fix | Delete
$this->classMap = array_merge($this->classMap, $classMap);
[94] Fix | Delete
} else {
[95] Fix | Delete
$this->classMap = $classMap;
[96] Fix | Delete
}
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Registers a set of PSR-0 directories for a given prefix, either
[101] Fix | Delete
* appending or prepending to the ones previously set for this prefix.
[102] Fix | Delete
*
[103] Fix | Delete
* @param string $prefix The prefix
[104] Fix | Delete
* @param array|string $paths The PSR-0 root directories
[105] Fix | Delete
* @param bool $prepend Whether to prepend the directories
[106] Fix | Delete
*/
[107] Fix | Delete
public function add($prefix, $paths, $prepend = false)
[108] Fix | Delete
{
[109] Fix | Delete
if (!$prefix) {
[110] Fix | Delete
if ($prepend) {
[111] Fix | Delete
$this->fallbackDirsPsr0 = array_merge(
[112] Fix | Delete
(array) $paths,
[113] Fix | Delete
$this->fallbackDirsPsr0
[114] Fix | Delete
);
[115] Fix | Delete
} else {
[116] Fix | Delete
$this->fallbackDirsPsr0 = array_merge(
[117] Fix | Delete
$this->fallbackDirsPsr0,
[118] Fix | Delete
(array) $paths
[119] Fix | Delete
);
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
return;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
$first = $prefix[0];
[126] Fix | Delete
if (!isset($this->prefixesPsr0[$first][$prefix])) {
[127] Fix | Delete
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
[128] Fix | Delete
[129] Fix | Delete
return;
[130] Fix | Delete
}
[131] Fix | Delete
if ($prepend) {
[132] Fix | Delete
$this->prefixesPsr0[$first][$prefix] = array_merge(
[133] Fix | Delete
(array) $paths,
[134] Fix | Delete
$this->prefixesPsr0[$first][$prefix]
[135] Fix | Delete
);
[136] Fix | Delete
} else {
[137] Fix | Delete
$this->prefixesPsr0[$first][$prefix] = array_merge(
[138] Fix | Delete
$this->prefixesPsr0[$first][$prefix],
[139] Fix | Delete
(array) $paths
[140] Fix | Delete
);
[141] Fix | Delete
}
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Registers a set of PSR-4 directories for a given namespace, either
[146] Fix | Delete
* appending or prepending to the ones previously set for this namespace.
[147] Fix | Delete
*
[148] Fix | Delete
* @param string $prefix The prefix/namespace, with trailing '\\'
[149] Fix | Delete
* @param array|string $paths The PSR-4 base directories
[150] Fix | Delete
* @param bool $prepend Whether to prepend the directories
[151] Fix | Delete
*
[152] Fix | Delete
* @throws \InvalidArgumentException
[153] Fix | Delete
*/
[154] Fix | Delete
public function addPsr4($prefix, $paths, $prepend = false)
[155] Fix | Delete
{
[156] Fix | Delete
if (!$prefix) {
[157] Fix | Delete
// Register directories for the root namespace.
[158] Fix | Delete
if ($prepend) {
[159] Fix | Delete
$this->fallbackDirsPsr4 = array_merge(
[160] Fix | Delete
(array) $paths,
[161] Fix | Delete
$this->fallbackDirsPsr4
[162] Fix | Delete
);
[163] Fix | Delete
} else {
[164] Fix | Delete
$this->fallbackDirsPsr4 = array_merge(
[165] Fix | Delete
$this->fallbackDirsPsr4,
[166] Fix | Delete
(array) $paths
[167] Fix | Delete
);
[168] Fix | Delete
}
[169] Fix | Delete
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
[170] Fix | Delete
// Register directories for a new namespace.
[171] Fix | Delete
$length = strlen($prefix);
[172] Fix | Delete
if ('\\' !== $prefix[$length - 1]) {
[173] Fix | Delete
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
[174] Fix | Delete
}
[175] Fix | Delete
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
[176] Fix | Delete
$this->prefixDirsPsr4[$prefix] = (array) $paths;
[177] Fix | Delete
} elseif ($prepend) {
[178] Fix | Delete
// Prepend directories for an already registered namespace.
[179] Fix | Delete
$this->prefixDirsPsr4[$prefix] = array_merge(
[180] Fix | Delete
(array) $paths,
[181] Fix | Delete
$this->prefixDirsPsr4[$prefix]
[182] Fix | Delete
);
[183] Fix | Delete
} else {
[184] Fix | Delete
// Append directories for an already registered namespace.
[185] Fix | Delete
$this->prefixDirsPsr4[$prefix] = array_merge(
[186] Fix | Delete
$this->prefixDirsPsr4[$prefix],
[187] Fix | Delete
(array) $paths
[188] Fix | Delete
);
[189] Fix | Delete
}
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Registers a set of PSR-0 directories for a given prefix,
[194] Fix | Delete
* replacing any others previously set for this prefix.
[195] Fix | Delete
*
[196] Fix | Delete
* @param string $prefix The prefix
[197] Fix | Delete
* @param array|string $paths The PSR-0 base directories
[198] Fix | Delete
*/
[199] Fix | Delete
public function set($prefix, $paths)
[200] Fix | Delete
{
[201] Fix | Delete
if (!$prefix) {
[202] Fix | Delete
$this->fallbackDirsPsr0 = (array) $paths;
[203] Fix | Delete
} else {
[204] Fix | Delete
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
[205] Fix | Delete
}
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
/**
[209] Fix | Delete
* Registers a set of PSR-4 directories for a given namespace,
[210] Fix | Delete
* replacing any others previously set for this namespace.
[211] Fix | Delete
*
[212] Fix | Delete
* @param string $prefix The prefix/namespace, with trailing '\\'
[213] Fix | Delete
* @param array|string $paths The PSR-4 base directories
[214] Fix | Delete
*
[215] Fix | Delete
* @throws \InvalidArgumentException
[216] Fix | Delete
*/
[217] Fix | Delete
public function setPsr4($prefix, $paths)
[218] Fix | Delete
{
[219] Fix | Delete
if (!$prefix) {
[220] Fix | Delete
$this->fallbackDirsPsr4 = (array) $paths;
[221] Fix | Delete
} else {
[222] Fix | Delete
$length = strlen($prefix);
[223] Fix | Delete
if ('\\' !== $prefix[$length - 1]) {
[224] Fix | Delete
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
[225] Fix | Delete
}
[226] Fix | Delete
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
[227] Fix | Delete
$this->prefixDirsPsr4[$prefix] = (array) $paths;
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* Turns on searching the include path for class files.
[233] Fix | Delete
*
[234] Fix | Delete
* @param bool $useIncludePath
[235] Fix | Delete
*/
[236] Fix | Delete
public function setUseIncludePath($useIncludePath)
[237] Fix | Delete
{
[238] Fix | Delete
$this->useIncludePath = $useIncludePath;
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
/**
[242] Fix | Delete
* Can be used to check if the autoloader uses the include path to check
[243] Fix | Delete
* for classes.
[244] Fix | Delete
*
[245] Fix | Delete
* @return bool
[246] Fix | Delete
*/
[247] Fix | Delete
public function getUseIncludePath()
[248] Fix | Delete
{
[249] Fix | Delete
return $this->useIncludePath;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* Turns off searching the prefix and fallback directories for classes
[254] Fix | Delete
* that have not been registered with the class map.
[255] Fix | Delete
*
[256] Fix | Delete
* @param bool $classMapAuthoritative
[257] Fix | Delete
*/
[258] Fix | Delete
public function setClassMapAuthoritative($classMapAuthoritative)
[259] Fix | Delete
{
[260] Fix | Delete
$this->classMapAuthoritative = $classMapAuthoritative;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Should class lookup fail if not found in the current class map?
[265] Fix | Delete
*
[266] Fix | Delete
* @return bool
[267] Fix | Delete
*/
[268] Fix | Delete
public function isClassMapAuthoritative()
[269] Fix | Delete
{
[270] Fix | Delete
return $this->classMapAuthoritative;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
[275] Fix | Delete
*
[276] Fix | Delete
* @param string|null $apcuPrefix
[277] Fix | Delete
*/
[278] Fix | Delete
public function setApcuPrefix($apcuPrefix)
[279] Fix | Delete
{
[280] Fix | Delete
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
/**
[284] Fix | Delete
* The APCu prefix in use, or null if APCu caching is not enabled.
[285] Fix | Delete
*
[286] Fix | Delete
* @return string|null
[287] Fix | Delete
*/
[288] Fix | Delete
public function getApcuPrefix()
[289] Fix | Delete
{
[290] Fix | Delete
return $this->apcuPrefix;
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
/**
[294] Fix | Delete
* Registers this instance as an autoloader.
[295] Fix | Delete
*
[296] Fix | Delete
* @param bool $prepend Whether to prepend the autoloader or not
[297] Fix | Delete
*/
[298] Fix | Delete
public function register($prepend = false)
[299] Fix | Delete
{
[300] Fix | Delete
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
/**
[304] Fix | Delete
* Unregisters this instance as an autoloader.
[305] Fix | Delete
*/
[306] Fix | Delete
public function unregister()
[307] Fix | Delete
{
[308] Fix | Delete
spl_autoload_unregister(array($this, 'loadClass'));
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
/**
[312] Fix | Delete
* Loads the given class or interface.
[313] Fix | Delete
*
[314] Fix | Delete
* @param string $class The name of the class
[315] Fix | Delete
* @return bool|null True if loaded, null otherwise
[316] Fix | Delete
*/
[317] Fix | Delete
public function loadClass($class)
[318] Fix | Delete
{
[319] Fix | Delete
if ($file = $this->findFile($class)) {
[320] Fix | Delete
includeFile($file);
[321] Fix | Delete
[322] Fix | Delete
return true;
[323] Fix | Delete
}
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
/**
[327] Fix | Delete
* Finds the path to the file where the class is defined.
[328] Fix | Delete
*
[329] Fix | Delete
* @param string $class The name of the class
[330] Fix | Delete
*
[331] Fix | Delete
* @return string|false The path if found, false otherwise
[332] Fix | Delete
*/
[333] Fix | Delete
public function findFile($class)
[334] Fix | Delete
{
[335] Fix | Delete
// class map lookup
[336] Fix | Delete
if (isset($this->classMap[$class])) {
[337] Fix | Delete
return $this->classMap[$class];
[338] Fix | Delete
}
[339] Fix | Delete
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
[340] Fix | Delete
return false;
[341] Fix | Delete
}
[342] Fix | Delete
if (null !== $this->apcuPrefix) {
[343] Fix | Delete
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
[344] Fix | Delete
if ($hit) {
[345] Fix | Delete
return $file;
[346] Fix | Delete
}
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
$file = $this->findFileWithExtension($class, '.php');
[350] Fix | Delete
[351] Fix | Delete
// Search for Hack files if we are running on HHVM
[352] Fix | Delete
if (false === $file && defined('HHVM_VERSION')) {
[353] Fix | Delete
$file = $this->findFileWithExtension($class, '.hh');
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
if (null !== $this->apcuPrefix) {
[357] Fix | Delete
apcu_add($this->apcuPrefix.$class, $file);
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
if (false === $file) {
[361] Fix | Delete
// Remember that this class does not exist.
[362] Fix | Delete
$this->missingClasses[$class] = true;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
return $file;
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
private function findFileWithExtension($class, $ext)
[369] Fix | Delete
{
[370] Fix | Delete
// PSR-4 lookup
[371] Fix | Delete
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
[372] Fix | Delete
[373] Fix | Delete
$first = $class[0];
[374] Fix | Delete
if (isset($this->prefixLengthsPsr4[$first])) {
[375] Fix | Delete
$subPath = $class;
[376] Fix | Delete
while (false !== $lastPos = strrpos($subPath, '\\')) {
[377] Fix | Delete
$subPath = substr($subPath, 0, $lastPos);
[378] Fix | Delete
$search = $subPath . '\\';
[379] Fix | Delete
if (isset($this->prefixDirsPsr4[$search])) {
[380] Fix | Delete
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
[381] Fix | Delete
foreach ($this->prefixDirsPsr4[$search] as $dir) {
[382] Fix | Delete
if (file_exists($file = $dir . $pathEnd)) {
[383] Fix | Delete
return $file;
[384] Fix | Delete
}
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
}
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
// PSR-4 fallback dirs
[391] Fix | Delete
foreach ($this->fallbackDirsPsr4 as $dir) {
[392] Fix | Delete
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
[393] Fix | Delete
return $file;
[394] Fix | Delete
}
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
// PSR-0 lookup
[398] Fix | Delete
if (false !== $pos = strrpos($class, '\\')) {
[399] Fix | Delete
// namespaced class name
[400] Fix | Delete
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
[401] Fix | Delete
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
[402] Fix | Delete
} else {
[403] Fix | Delete
// PEAR-like class name
[404] Fix | Delete
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
if (isset($this->prefixesPsr0[$first])) {
[408] Fix | Delete
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
[409] Fix | Delete
if (0 === strpos($class, $prefix)) {
[410] Fix | Delete
foreach ($dirs as $dir) {
[411] Fix | Delete
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
[412] Fix | Delete
return $file;
[413] Fix | Delete
}
[414] Fix | Delete
}
[415] Fix | Delete
}
[416] Fix | Delete
}
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
// PSR-0 fallback dirs
[420] Fix | Delete
foreach ($this->fallbackDirsPsr0 as $dir) {
[421] Fix | Delete
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
[422] Fix | Delete
return $file;
[423] Fix | Delete
}
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
// PSR-0 include paths.
[427] Fix | Delete
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
[428] Fix | Delete
return $file;
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
return false;
[432] Fix | Delete
}
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
/**
[436] Fix | Delete
* Scope isolated include.
[437] Fix | Delete
*
[438] Fix | Delete
* Prevents access to $this/self from included files.
[439] Fix | Delete
*/
[440] Fix | Delete
function includeFile($file)
[441] Fix | Delete
{
[442] Fix | Delete
include $file;
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function