1605f8e8dSAndreas Gohr<?php 2605f8e8dSAndreas Gohr 3605f8e8dSAndreas Gohr/* 4605f8e8dSAndreas Gohr * This file is part of Composer. 5605f8e8dSAndreas Gohr * 6605f8e8dSAndreas Gohr * (c) Nils Adermann <naderman@naderman.de> 7605f8e8dSAndreas Gohr * Jordi Boggiano <j.boggiano@seld.be> 8605f8e8dSAndreas Gohr * 9605f8e8dSAndreas Gohr * For the full copyright and license information, please view the LICENSE 10605f8e8dSAndreas Gohr * file that was distributed with this source code. 11605f8e8dSAndreas Gohr */ 12605f8e8dSAndreas Gohr 13605f8e8dSAndreas Gohrnamespace Composer\Autoload; 14605f8e8dSAndreas Gohr 15605f8e8dSAndreas Gohr/** 16*7a33d2f8SNiklas Keller * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. 17605f8e8dSAndreas Gohr * 18605f8e8dSAndreas Gohr * $loader = new \Composer\Autoload\ClassLoader(); 19605f8e8dSAndreas Gohr * 20605f8e8dSAndreas Gohr * // register classes with namespaces 21605f8e8dSAndreas Gohr * $loader->add('Symfony\Component', __DIR__.'/component'); 22605f8e8dSAndreas Gohr * $loader->add('Symfony', __DIR__.'/framework'); 23605f8e8dSAndreas Gohr * 24605f8e8dSAndreas Gohr * // activate the autoloader 25605f8e8dSAndreas Gohr * $loader->register(); 26605f8e8dSAndreas Gohr * 27605f8e8dSAndreas Gohr * // to enable searching the include path (eg. for PEAR packages) 28605f8e8dSAndreas Gohr * $loader->setUseIncludePath(true); 29605f8e8dSAndreas Gohr * 30605f8e8dSAndreas Gohr * In this example, if you try to use a class in the Symfony\Component 31605f8e8dSAndreas Gohr * namespace or one of its children (Symfony\Component\Console for instance), 32605f8e8dSAndreas Gohr * the autoloader will first look for the class under the component/ 33605f8e8dSAndreas Gohr * directory, and it will then fallback to the framework/ directory if not 34605f8e8dSAndreas Gohr * found before giving up. 35605f8e8dSAndreas Gohr * 36605f8e8dSAndreas Gohr * This class is loosely based on the Symfony UniversalClassLoader. 37605f8e8dSAndreas Gohr * 38605f8e8dSAndreas Gohr * @author Fabien Potencier <fabien@symfony.com> 39605f8e8dSAndreas Gohr * @author Jordi Boggiano <j.boggiano@seld.be> 40*7a33d2f8SNiklas Keller * @see http://www.php-fig.org/psr/psr-0/ 41*7a33d2f8SNiklas Keller * @see http://www.php-fig.org/psr/psr-4/ 42605f8e8dSAndreas Gohr */ 43605f8e8dSAndreas Gohrclass ClassLoader 44605f8e8dSAndreas Gohr{ 45605f8e8dSAndreas Gohr // PSR-4 46605f8e8dSAndreas Gohr private $prefixLengthsPsr4 = array(); 47605f8e8dSAndreas Gohr private $prefixDirsPsr4 = array(); 48605f8e8dSAndreas Gohr private $fallbackDirsPsr4 = array(); 49605f8e8dSAndreas Gohr 50605f8e8dSAndreas Gohr // PSR-0 51605f8e8dSAndreas Gohr private $prefixesPsr0 = array(); 52605f8e8dSAndreas Gohr private $fallbackDirsPsr0 = array(); 53605f8e8dSAndreas Gohr 54605f8e8dSAndreas Gohr private $useIncludePath = false; 55605f8e8dSAndreas Gohr private $classMap = array(); 56605f8e8dSAndreas Gohr private $classMapAuthoritative = false; 57*7a33d2f8SNiklas Keller private $missingClasses = array(); 58605f8e8dSAndreas Gohr 59605f8e8dSAndreas Gohr public function getPrefixes() 60605f8e8dSAndreas Gohr { 61605f8e8dSAndreas Gohr if (!empty($this->prefixesPsr0)) { 62605f8e8dSAndreas Gohr return call_user_func_array('array_merge', $this->prefixesPsr0); 63605f8e8dSAndreas Gohr } 64605f8e8dSAndreas Gohr 65605f8e8dSAndreas Gohr return array(); 66605f8e8dSAndreas Gohr } 67605f8e8dSAndreas Gohr 68605f8e8dSAndreas Gohr public function getPrefixesPsr4() 69605f8e8dSAndreas Gohr { 70605f8e8dSAndreas Gohr return $this->prefixDirsPsr4; 71605f8e8dSAndreas Gohr } 72605f8e8dSAndreas Gohr 73605f8e8dSAndreas Gohr public function getFallbackDirs() 74605f8e8dSAndreas Gohr { 75605f8e8dSAndreas Gohr return $this->fallbackDirsPsr0; 76605f8e8dSAndreas Gohr } 77605f8e8dSAndreas Gohr 78605f8e8dSAndreas Gohr public function getFallbackDirsPsr4() 79605f8e8dSAndreas Gohr { 80605f8e8dSAndreas Gohr return $this->fallbackDirsPsr4; 81605f8e8dSAndreas Gohr } 82605f8e8dSAndreas Gohr 83605f8e8dSAndreas Gohr public function getClassMap() 84605f8e8dSAndreas Gohr { 85605f8e8dSAndreas Gohr return $this->classMap; 86605f8e8dSAndreas Gohr } 87605f8e8dSAndreas Gohr 88605f8e8dSAndreas Gohr /** 89605f8e8dSAndreas Gohr * @param array $classMap Class to filename map 90605f8e8dSAndreas Gohr */ 91605f8e8dSAndreas Gohr public function addClassMap(array $classMap) 92605f8e8dSAndreas Gohr { 93605f8e8dSAndreas Gohr if ($this->classMap) { 94605f8e8dSAndreas Gohr $this->classMap = array_merge($this->classMap, $classMap); 95605f8e8dSAndreas Gohr } else { 96605f8e8dSAndreas Gohr $this->classMap = $classMap; 97605f8e8dSAndreas Gohr } 98605f8e8dSAndreas Gohr } 99605f8e8dSAndreas Gohr 100605f8e8dSAndreas Gohr /** 101605f8e8dSAndreas Gohr * Registers a set of PSR-0 directories for a given prefix, either 102605f8e8dSAndreas Gohr * appending or prepending to the ones previously set for this prefix. 103605f8e8dSAndreas Gohr * 104605f8e8dSAndreas Gohr * @param string $prefix The prefix 105605f8e8dSAndreas Gohr * @param array|string $paths The PSR-0 root directories 106605f8e8dSAndreas Gohr * @param bool $prepend Whether to prepend the directories 107605f8e8dSAndreas Gohr */ 108605f8e8dSAndreas Gohr public function add($prefix, $paths, $prepend = false) 109605f8e8dSAndreas Gohr { 110605f8e8dSAndreas Gohr if (!$prefix) { 111605f8e8dSAndreas Gohr if ($prepend) { 112605f8e8dSAndreas Gohr $this->fallbackDirsPsr0 = array_merge( 113605f8e8dSAndreas Gohr (array) $paths, 114605f8e8dSAndreas Gohr $this->fallbackDirsPsr0 115605f8e8dSAndreas Gohr ); 116605f8e8dSAndreas Gohr } else { 117605f8e8dSAndreas Gohr $this->fallbackDirsPsr0 = array_merge( 118605f8e8dSAndreas Gohr $this->fallbackDirsPsr0, 119605f8e8dSAndreas Gohr (array) $paths 120605f8e8dSAndreas Gohr ); 121605f8e8dSAndreas Gohr } 122605f8e8dSAndreas Gohr 123605f8e8dSAndreas Gohr return; 124605f8e8dSAndreas Gohr } 125605f8e8dSAndreas Gohr 126605f8e8dSAndreas Gohr $first = $prefix[0]; 127605f8e8dSAndreas Gohr if (!isset($this->prefixesPsr0[$first][$prefix])) { 128605f8e8dSAndreas Gohr $this->prefixesPsr0[$first][$prefix] = (array) $paths; 129605f8e8dSAndreas Gohr 130605f8e8dSAndreas Gohr return; 131605f8e8dSAndreas Gohr } 132605f8e8dSAndreas Gohr if ($prepend) { 133605f8e8dSAndreas Gohr $this->prefixesPsr0[$first][$prefix] = array_merge( 134605f8e8dSAndreas Gohr (array) $paths, 135605f8e8dSAndreas Gohr $this->prefixesPsr0[$first][$prefix] 136605f8e8dSAndreas Gohr ); 137605f8e8dSAndreas Gohr } else { 138605f8e8dSAndreas Gohr $this->prefixesPsr0[$first][$prefix] = array_merge( 139605f8e8dSAndreas Gohr $this->prefixesPsr0[$first][$prefix], 140605f8e8dSAndreas Gohr (array) $paths 141605f8e8dSAndreas Gohr ); 142605f8e8dSAndreas Gohr } 143605f8e8dSAndreas Gohr } 144605f8e8dSAndreas Gohr 145605f8e8dSAndreas Gohr /** 146605f8e8dSAndreas Gohr * Registers a set of PSR-4 directories for a given namespace, either 147605f8e8dSAndreas Gohr * appending or prepending to the ones previously set for this namespace. 148605f8e8dSAndreas Gohr * 149605f8e8dSAndreas Gohr * @param string $prefix The prefix/namespace, with trailing '\\' 150*7a33d2f8SNiklas Keller * @param array|string $paths The PSR-4 base directories 151605f8e8dSAndreas Gohr * @param bool $prepend Whether to prepend the directories 152605f8e8dSAndreas Gohr * 153605f8e8dSAndreas Gohr * @throws \InvalidArgumentException 154605f8e8dSAndreas Gohr */ 155605f8e8dSAndreas Gohr public function addPsr4($prefix, $paths, $prepend = false) 156605f8e8dSAndreas Gohr { 157605f8e8dSAndreas Gohr if (!$prefix) { 158605f8e8dSAndreas Gohr // Register directories for the root namespace. 159605f8e8dSAndreas Gohr if ($prepend) { 160605f8e8dSAndreas Gohr $this->fallbackDirsPsr4 = array_merge( 161605f8e8dSAndreas Gohr (array) $paths, 162605f8e8dSAndreas Gohr $this->fallbackDirsPsr4 163605f8e8dSAndreas Gohr ); 164605f8e8dSAndreas Gohr } else { 165605f8e8dSAndreas Gohr $this->fallbackDirsPsr4 = array_merge( 166605f8e8dSAndreas Gohr $this->fallbackDirsPsr4, 167605f8e8dSAndreas Gohr (array) $paths 168605f8e8dSAndreas Gohr ); 169605f8e8dSAndreas Gohr } 170605f8e8dSAndreas Gohr } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 171605f8e8dSAndreas Gohr // Register directories for a new namespace. 172605f8e8dSAndreas Gohr $length = strlen($prefix); 173605f8e8dSAndreas Gohr if ('\\' !== $prefix[$length - 1]) { 174605f8e8dSAndreas Gohr throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 175605f8e8dSAndreas Gohr } 176605f8e8dSAndreas Gohr $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 177605f8e8dSAndreas Gohr $this->prefixDirsPsr4[$prefix] = (array) $paths; 178605f8e8dSAndreas Gohr } elseif ($prepend) { 179605f8e8dSAndreas Gohr // Prepend directories for an already registered namespace. 180605f8e8dSAndreas Gohr $this->prefixDirsPsr4[$prefix] = array_merge( 181605f8e8dSAndreas Gohr (array) $paths, 182605f8e8dSAndreas Gohr $this->prefixDirsPsr4[$prefix] 183605f8e8dSAndreas Gohr ); 184605f8e8dSAndreas Gohr } else { 185605f8e8dSAndreas Gohr // Append directories for an already registered namespace. 186605f8e8dSAndreas Gohr $this->prefixDirsPsr4[$prefix] = array_merge( 187605f8e8dSAndreas Gohr $this->prefixDirsPsr4[$prefix], 188605f8e8dSAndreas Gohr (array) $paths 189605f8e8dSAndreas Gohr ); 190605f8e8dSAndreas Gohr } 191605f8e8dSAndreas Gohr } 192605f8e8dSAndreas Gohr 193605f8e8dSAndreas Gohr /** 194605f8e8dSAndreas Gohr * Registers a set of PSR-0 directories for a given prefix, 195605f8e8dSAndreas Gohr * replacing any others previously set for this prefix. 196605f8e8dSAndreas Gohr * 197605f8e8dSAndreas Gohr * @param string $prefix The prefix 198605f8e8dSAndreas Gohr * @param array|string $paths The PSR-0 base directories 199605f8e8dSAndreas Gohr */ 200605f8e8dSAndreas Gohr public function set($prefix, $paths) 201605f8e8dSAndreas Gohr { 202605f8e8dSAndreas Gohr if (!$prefix) { 203605f8e8dSAndreas Gohr $this->fallbackDirsPsr0 = (array) $paths; 204605f8e8dSAndreas Gohr } else { 205605f8e8dSAndreas Gohr $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 206605f8e8dSAndreas Gohr } 207605f8e8dSAndreas Gohr } 208605f8e8dSAndreas Gohr 209605f8e8dSAndreas Gohr /** 210605f8e8dSAndreas Gohr * Registers a set of PSR-4 directories for a given namespace, 211605f8e8dSAndreas Gohr * replacing any others previously set for this namespace. 212605f8e8dSAndreas Gohr * 213605f8e8dSAndreas Gohr * @param string $prefix The prefix/namespace, with trailing '\\' 214605f8e8dSAndreas Gohr * @param array|string $paths The PSR-4 base directories 215605f8e8dSAndreas Gohr * 216605f8e8dSAndreas Gohr * @throws \InvalidArgumentException 217605f8e8dSAndreas Gohr */ 218605f8e8dSAndreas Gohr public function setPsr4($prefix, $paths) 219605f8e8dSAndreas Gohr { 220605f8e8dSAndreas Gohr if (!$prefix) { 221605f8e8dSAndreas Gohr $this->fallbackDirsPsr4 = (array) $paths; 222605f8e8dSAndreas Gohr } else { 223605f8e8dSAndreas Gohr $length = strlen($prefix); 224605f8e8dSAndreas Gohr if ('\\' !== $prefix[$length - 1]) { 225605f8e8dSAndreas Gohr throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 226605f8e8dSAndreas Gohr } 227605f8e8dSAndreas Gohr $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 228605f8e8dSAndreas Gohr $this->prefixDirsPsr4[$prefix] = (array) $paths; 229605f8e8dSAndreas Gohr } 230605f8e8dSAndreas Gohr } 231605f8e8dSAndreas Gohr 232605f8e8dSAndreas Gohr /** 233605f8e8dSAndreas Gohr * Turns on searching the include path for class files. 234605f8e8dSAndreas Gohr * 235605f8e8dSAndreas Gohr * @param bool $useIncludePath 236605f8e8dSAndreas Gohr */ 237605f8e8dSAndreas Gohr public function setUseIncludePath($useIncludePath) 238605f8e8dSAndreas Gohr { 239605f8e8dSAndreas Gohr $this->useIncludePath = $useIncludePath; 240605f8e8dSAndreas Gohr } 241605f8e8dSAndreas Gohr 242605f8e8dSAndreas Gohr /** 243605f8e8dSAndreas Gohr * Can be used to check if the autoloader uses the include path to check 244605f8e8dSAndreas Gohr * for classes. 245605f8e8dSAndreas Gohr * 246605f8e8dSAndreas Gohr * @return bool 247605f8e8dSAndreas Gohr */ 248605f8e8dSAndreas Gohr public function getUseIncludePath() 249605f8e8dSAndreas Gohr { 250605f8e8dSAndreas Gohr return $this->useIncludePath; 251605f8e8dSAndreas Gohr } 252605f8e8dSAndreas Gohr 253605f8e8dSAndreas Gohr /** 254605f8e8dSAndreas Gohr * Turns off searching the prefix and fallback directories for classes 255605f8e8dSAndreas Gohr * that have not been registered with the class map. 256605f8e8dSAndreas Gohr * 257605f8e8dSAndreas Gohr * @param bool $classMapAuthoritative 258605f8e8dSAndreas Gohr */ 259605f8e8dSAndreas Gohr public function setClassMapAuthoritative($classMapAuthoritative) 260605f8e8dSAndreas Gohr { 261605f8e8dSAndreas Gohr $this->classMapAuthoritative = $classMapAuthoritative; 262605f8e8dSAndreas Gohr } 263605f8e8dSAndreas Gohr 264605f8e8dSAndreas Gohr /** 265605f8e8dSAndreas Gohr * Should class lookup fail if not found in the current class map? 266605f8e8dSAndreas Gohr * 267605f8e8dSAndreas Gohr * @return bool 268605f8e8dSAndreas Gohr */ 269605f8e8dSAndreas Gohr public function isClassMapAuthoritative() 270605f8e8dSAndreas Gohr { 271605f8e8dSAndreas Gohr return $this->classMapAuthoritative; 272605f8e8dSAndreas Gohr } 273605f8e8dSAndreas Gohr 274605f8e8dSAndreas Gohr /** 275605f8e8dSAndreas Gohr * Registers this instance as an autoloader. 276605f8e8dSAndreas Gohr * 277605f8e8dSAndreas Gohr * @param bool $prepend Whether to prepend the autoloader or not 278605f8e8dSAndreas Gohr */ 279605f8e8dSAndreas Gohr public function register($prepend = false) 280605f8e8dSAndreas Gohr { 281605f8e8dSAndreas Gohr spl_autoload_register(array($this, 'loadClass'), true, $prepend); 282605f8e8dSAndreas Gohr } 283605f8e8dSAndreas Gohr 284605f8e8dSAndreas Gohr /** 285605f8e8dSAndreas Gohr * Unregisters this instance as an autoloader. 286605f8e8dSAndreas Gohr */ 287605f8e8dSAndreas Gohr public function unregister() 288605f8e8dSAndreas Gohr { 289605f8e8dSAndreas Gohr spl_autoload_unregister(array($this, 'loadClass')); 290605f8e8dSAndreas Gohr } 291605f8e8dSAndreas Gohr 292605f8e8dSAndreas Gohr /** 293605f8e8dSAndreas Gohr * Loads the given class or interface. 294605f8e8dSAndreas Gohr * 295605f8e8dSAndreas Gohr * @param string $class The name of the class 296605f8e8dSAndreas Gohr * @return bool|null True if loaded, null otherwise 297605f8e8dSAndreas Gohr */ 298605f8e8dSAndreas Gohr public function loadClass($class) 299605f8e8dSAndreas Gohr { 300605f8e8dSAndreas Gohr if ($file = $this->findFile($class)) { 301605f8e8dSAndreas Gohr includeFile($file); 302605f8e8dSAndreas Gohr 303605f8e8dSAndreas Gohr return true; 304605f8e8dSAndreas Gohr } 305605f8e8dSAndreas Gohr } 306605f8e8dSAndreas Gohr 307605f8e8dSAndreas Gohr /** 308605f8e8dSAndreas Gohr * Finds the path to the file where the class is defined. 309605f8e8dSAndreas Gohr * 310605f8e8dSAndreas Gohr * @param string $class The name of the class 311605f8e8dSAndreas Gohr * 312605f8e8dSAndreas Gohr * @return string|false The path if found, false otherwise 313605f8e8dSAndreas Gohr */ 314605f8e8dSAndreas Gohr public function findFile($class) 315605f8e8dSAndreas Gohr { 316605f8e8dSAndreas Gohr // class map lookup 317605f8e8dSAndreas Gohr if (isset($this->classMap[$class])) { 318605f8e8dSAndreas Gohr return $this->classMap[$class]; 319605f8e8dSAndreas Gohr } 320*7a33d2f8SNiklas Keller if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { 321605f8e8dSAndreas Gohr return false; 322605f8e8dSAndreas Gohr } 323605f8e8dSAndreas Gohr 324605f8e8dSAndreas Gohr $file = $this->findFileWithExtension($class, '.php'); 325605f8e8dSAndreas Gohr 326605f8e8dSAndreas Gohr // Search for Hack files if we are running on HHVM 327*7a33d2f8SNiklas Keller if (false === $file && defined('HHVM_VERSION')) { 328605f8e8dSAndreas Gohr $file = $this->findFileWithExtension($class, '.hh'); 329605f8e8dSAndreas Gohr } 330605f8e8dSAndreas Gohr 331*7a33d2f8SNiklas Keller if (false === $file) { 332605f8e8dSAndreas Gohr // Remember that this class does not exist. 333*7a33d2f8SNiklas Keller $this->missingClasses[$class] = true; 334605f8e8dSAndreas Gohr } 335605f8e8dSAndreas Gohr 336605f8e8dSAndreas Gohr return $file; 337605f8e8dSAndreas Gohr } 338605f8e8dSAndreas Gohr 339605f8e8dSAndreas Gohr private function findFileWithExtension($class, $ext) 340605f8e8dSAndreas Gohr { 341605f8e8dSAndreas Gohr // PSR-4 lookup 342605f8e8dSAndreas Gohr $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 343605f8e8dSAndreas Gohr 344605f8e8dSAndreas Gohr $first = $class[0]; 345605f8e8dSAndreas Gohr if (isset($this->prefixLengthsPsr4[$first])) { 346605f8e8dSAndreas Gohr foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { 347605f8e8dSAndreas Gohr if (0 === strpos($class, $prefix)) { 348605f8e8dSAndreas Gohr foreach ($this->prefixDirsPsr4[$prefix] as $dir) { 349*7a33d2f8SNiklas Keller if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { 350605f8e8dSAndreas Gohr return $file; 351605f8e8dSAndreas Gohr } 352605f8e8dSAndreas Gohr } 353605f8e8dSAndreas Gohr } 354605f8e8dSAndreas Gohr } 355605f8e8dSAndreas Gohr } 356605f8e8dSAndreas Gohr 357605f8e8dSAndreas Gohr // PSR-4 fallback dirs 358605f8e8dSAndreas Gohr foreach ($this->fallbackDirsPsr4 as $dir) { 359*7a33d2f8SNiklas Keller if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 360605f8e8dSAndreas Gohr return $file; 361605f8e8dSAndreas Gohr } 362605f8e8dSAndreas Gohr } 363605f8e8dSAndreas Gohr 364605f8e8dSAndreas Gohr // PSR-0 lookup 365605f8e8dSAndreas Gohr if (false !== $pos = strrpos($class, '\\')) { 366605f8e8dSAndreas Gohr // namespaced class name 367605f8e8dSAndreas Gohr $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 368605f8e8dSAndreas Gohr . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 369605f8e8dSAndreas Gohr } else { 370605f8e8dSAndreas Gohr // PEAR-like class name 371605f8e8dSAndreas Gohr $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 372605f8e8dSAndreas Gohr } 373605f8e8dSAndreas Gohr 374605f8e8dSAndreas Gohr if (isset($this->prefixesPsr0[$first])) { 375605f8e8dSAndreas Gohr foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 376605f8e8dSAndreas Gohr if (0 === strpos($class, $prefix)) { 377605f8e8dSAndreas Gohr foreach ($dirs as $dir) { 378*7a33d2f8SNiklas Keller if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 379605f8e8dSAndreas Gohr return $file; 380605f8e8dSAndreas Gohr } 381605f8e8dSAndreas Gohr } 382605f8e8dSAndreas Gohr } 383605f8e8dSAndreas Gohr } 384605f8e8dSAndreas Gohr } 385605f8e8dSAndreas Gohr 386605f8e8dSAndreas Gohr // PSR-0 fallback dirs 387605f8e8dSAndreas Gohr foreach ($this->fallbackDirsPsr0 as $dir) { 388*7a33d2f8SNiklas Keller if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 389605f8e8dSAndreas Gohr return $file; 390605f8e8dSAndreas Gohr } 391605f8e8dSAndreas Gohr } 392605f8e8dSAndreas Gohr 393605f8e8dSAndreas Gohr // PSR-0 include paths. 394605f8e8dSAndreas Gohr if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 395605f8e8dSAndreas Gohr return $file; 396605f8e8dSAndreas Gohr } 397*7a33d2f8SNiklas Keller 398*7a33d2f8SNiklas Keller return false; 399605f8e8dSAndreas Gohr } 400605f8e8dSAndreas Gohr} 401605f8e8dSAndreas Gohr 402605f8e8dSAndreas Gohr/** 403605f8e8dSAndreas Gohr * Scope isolated include. 404605f8e8dSAndreas Gohr * 405605f8e8dSAndreas Gohr * Prevents access to $this/self from included files. 406605f8e8dSAndreas Gohr */ 407605f8e8dSAndreas Gohrfunction includeFile($file) 408605f8e8dSAndreas Gohr{ 409605f8e8dSAndreas Gohr include $file; 410605f8e8dSAndreas Gohr} 411