ComposerAutoloadClassLoader

ClassLoader implements a PSR-0 class loader.

Defined (2)

The class is defined in the following location(s).

/vendor/calderawp/metaplate-core/vendor/composer/ClassLoader.php  
  1. class ClassLoader 
  2. // PSR-4 
  3. private $prefixLengthsPsr4 = array(); 
  4. private $prefixDirsPsr4 = array(); 
  5. private $fallbackDirsPsr4 = array(); 
  6.  
  7. // PSR-0 
  8. private $prefixesPsr0 = array(); 
  9. private $fallbackDirsPsr0 = array(); 
  10.  
  11. private $useIncludePath = false; 
  12. private $classMap = array(); 
  13.  
  14. public function getPrefixes() 
  15. return call_user_func_array('array_merge', $this->prefixesPsr0); 
  16.  
  17. public function getPrefixesPsr4() 
  18. return $this->prefixDirsPsr4; 
  19.  
  20. public function getFallbackDirs() 
  21. return $this->fallbackDirsPsr0; 
  22.  
  23. public function getFallbackDirsPsr4() 
  24. return $this->fallbackDirsPsr4; 
  25.  
  26. public function getClassMap() 
  27. return $this->classMap; 
  28.  
  29. /** 
  30. * @param array $classMap Class to filename map 
  31. */ 
  32. public function addClassMap(array $classMap) 
  33. if ($this->classMap) { 
  34. $this->classMap = array_merge($this->classMap, $classMap); 
  35. } else { 
  36. $this->classMap = $classMap; 
  37.  
  38. /** 
  39. * Registers a set of PSR-0 directories for a given prefix, either 
  40. * appending or prepending to the ones previously set for this prefix. 
  41. * @param string $prefix The prefix 
  42. * @param array|string $paths The PSR-0 root directories 
  43. * @param bool $prepend Whether to prepend the directories 
  44. */ 
  45. public function add($prefix, $paths, $prepend = false) 
  46. if (!$prefix) { 
  47. if ($prepend) { 
  48. $this->fallbackDirsPsr0 = array_merge( 
  49. (array) $paths,  
  50. $this->fallbackDirsPsr0 
  51. ); 
  52. } else { 
  53. $this->fallbackDirsPsr0 = array_merge( 
  54. $this->fallbackDirsPsr0,  
  55. (array) $paths 
  56. ); 
  57.  
  58. return; 
  59.  
  60. $first = $prefix[0]; 
  61. if (!isset($this->prefixesPsr0[$first][$prefix])) { 
  62. $this->prefixesPsr0[$first][$prefix] = (array) $paths; 
  63.  
  64. return; 
  65. if ($prepend) { 
  66. $this->prefixesPsr0[$first][$prefix] = array_merge( 
  67. (array) $paths,  
  68. $this->prefixesPsr0[$first][$prefix] 
  69. ); 
  70. } else { 
  71. $this->prefixesPsr0[$first][$prefix] = array_merge( 
  72. $this->prefixesPsr0[$first][$prefix],  
  73. (array) $paths 
  74. ); 
  75.  
  76. /** 
  77. * Registers a set of PSR-4 directories for a given namespace, either 
  78. * appending or prepending to the ones previously set for this namespace. 
  79. * @param string $prefix The prefix/namespace, with trailing '\\' 
  80. * @param array|string $paths The PSR-0 base directories 
  81. * @param bool $prepend Whether to prepend the directories 
  82. * @throws \InvalidArgumentException 
  83. */ 
  84. public function addPsr4($prefix, $paths, $prepend = false) 
  85. if (!$prefix) { 
  86. // Register directories for the root namespace. 
  87. if ($prepend) { 
  88. $this->fallbackDirsPsr4 = array_merge( 
  89. (array) $paths,  
  90. $this->fallbackDirsPsr4 
  91. ); 
  92. } else { 
  93. $this->fallbackDirsPsr4 = array_merge( 
  94. $this->fallbackDirsPsr4,  
  95. (array) $paths 
  96. ); 
  97. } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 
  98. // Register directories for a new namespace. 
  99. $length = strlen($prefix); 
  100. if ('\\' !== $prefix[$length - 1]) { 
  101. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 
  102. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 
  103. $this->prefixDirsPsr4[$prefix] = (array) $paths; 
  104. } elseif ($prepend) { 
  105. // Prepend directories for an already registered namespace. 
  106. $this->prefixDirsPsr4[$prefix] = array_merge( 
  107. (array) $paths,  
  108. $this->prefixDirsPsr4[$prefix] 
  109. ); 
  110. } else { 
  111. // Append directories for an already registered namespace. 
  112. $this->prefixDirsPsr4[$prefix] = array_merge( 
  113. $this->prefixDirsPsr4[$prefix],  
  114. (array) $paths 
  115. ); 
  116.  
  117. /** 
  118. * Registers a set of PSR-0 directories for a given prefix,  
  119. * replacing any others previously set for this prefix. 
  120. * @param string $prefix The prefix 
  121. * @param array|string $paths The PSR-0 base directories 
  122. */ 
  123. public function set($prefix, $paths) 
  124. if (!$prefix) { 
  125. $this->fallbackDirsPsr0 = (array) $paths; 
  126. } else { 
  127. $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 
  128.  
  129. /** 
  130. * Registers a set of PSR-4 directories for a given namespace,  
  131. * replacing any others previously set for this namespace. 
  132. * @param string $prefix The prefix/namespace, with trailing '\\' 
  133. * @param array|string $paths The PSR-4 base directories 
  134. * @throws \InvalidArgumentException 
  135. */ 
  136. public function setPsr4($prefix, $paths) 
  137. if (!$prefix) { 
  138. $this->fallbackDirsPsr4 = (array) $paths; 
  139. } else { 
  140. $length = strlen($prefix); 
  141. if ('\\' !== $prefix[$length - 1]) { 
  142. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 
  143. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 
  144. $this->prefixDirsPsr4[$prefix] = (array) $paths; 
  145.  
  146. /** 
  147. * Turns on searching the include path for class files. 
  148. * @param bool $useIncludePath 
  149. */ 
  150. public function setUseIncludePath($useIncludePath) 
  151. $this->useIncludePath = $useIncludePath; 
  152.  
  153. /** 
  154. * Can be used to check if the autoloader uses the include path to check 
  155. * for classes. 
  156. * @return bool 
  157. */ 
  158. public function getUseIncludePath() 
  159. return $this->useIncludePath; 
  160.  
  161. /** 
  162. * Registers this instance as an autoloader. 
  163. * @param bool $prepend Whether to prepend the autoloader or not 
  164. */ 
  165. public function register($prepend = false) 
  166. spl_autoload_register(array($this, 'loadClass'), true, $prepend); 
  167.  
  168. /** 
  169. * Unregisters this instance as an autoloader. 
  170. */ 
  171. public function unregister() 
  172. spl_autoload_unregister(array($this, 'loadClass')); 
  173.  
  174. /** 
  175. * Loads the given class or interface. 
  176. * @param string $class The name of the class 
  177. * @return bool|null True if loaded, null otherwise 
  178. */ 
  179. public function loadClass($class) 
  180. if ($file = $this->findFile($class)) { 
  181. includeFile($file); 
  182.  
  183. return true; 
  184.  
  185. /** 
  186. * Finds the path to the file where the class is defined. 
  187. * @param string $class The name of the class 
  188. * @return string|false The path if found, false otherwise 
  189. */ 
  190. public function findFile($class) 
  191. // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 
  192. if ('\\' == $class[0]) { 
  193. $class = substr($class, 1); 
  194.  
  195. // class map lookup 
  196. if (isset($this->classMap[$class])) { 
  197. return $this->classMap[$class]; 
  198.  
  199. $file = $this->findFileWithExtension($class, '.php'); 
  200.  
  201. // Search for Hack files if we are running on HHVM 
  202. if ($file === null && defined('HHVM_VERSION')) { 
  203. $file = $this->findFileWithExtension($class, '.hh'); 
  204.  
  205. if ($file === null) { 
  206. // Remember that this class does not exist. 
  207. return $this->classMap[$class] = false; 
  208.  
  209. return $file; 
  210.  
  211. private function findFileWithExtension($class, $ext) 
  212. // PSR-4 lookup 
  213. $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 
  214.  
  215. $first = $class[0]; 
  216. if (isset($this->prefixLengthsPsr4[$first])) { 
  217. foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { 
  218. if (0 === strpos($class, $prefix)) { 
  219. foreach ($this->prefixDirsPsr4[$prefix] as $dir) { 
  220. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { 
  221. return $file; 
  222.  
  223. // PSR-4 fallback dirs 
  224. foreach ($this->fallbackDirsPsr4 as $dir) { 
  225. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 
  226. return $file; 
  227.  
  228. // PSR-0 lookup 
  229. if (false !== $pos = strrpos($class, '\\')) { 
  230. // namespaced class name 
  231. $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 
  232. . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 
  233. } else { 
  234. // PEAR-like class name 
  235. $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 
  236.  
  237. if (isset($this->prefixesPsr0[$first])) { 
  238. foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 
  239. if (0 === strpos($class, $prefix)) { 
  240. foreach ($dirs as $dir) { 
  241. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 
  242. return $file; 
  243.  
  244. // PSR-0 fallback dirs 
  245. foreach ($this->fallbackDirsPsr0 as $dir) { 
  246. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 
  247. return $file; 
  248.  
  249. // PSR-0 include paths. 
  250. if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 
  251. return $file; 
/vendor/composer/ClassLoader.php  
  1. class ClassLoader 
  2. // PSR-4 
  3. private $prefixLengthsPsr4 = array(); 
  4. private $prefixDirsPsr4 = array(); 
  5. private $fallbackDirsPsr4 = array(); 
  6.  
  7. // PSR-0 
  8. private $prefixesPsr0 = array(); 
  9. private $fallbackDirsPsr0 = array(); 
  10.  
  11. private $useIncludePath = false; 
  12. private $classMap = array(); 
  13.  
  14. public function getPrefixes() 
  15. if (!empty($this->prefixesPsr0)) { 
  16. return call_user_func_array('array_merge', $this->prefixesPsr0); 
  17.  
  18. return array(); 
  19.  
  20. public function getPrefixesPsr4() 
  21. return $this->prefixDirsPsr4; 
  22.  
  23. public function getFallbackDirs() 
  24. return $this->fallbackDirsPsr0; 
  25.  
  26. public function getFallbackDirsPsr4() 
  27. return $this->fallbackDirsPsr4; 
  28.  
  29. public function getClassMap() 
  30. return $this->classMap; 
  31.  
  32. /** 
  33. * @param array $classMap Class to filename map 
  34. */ 
  35. public function addClassMap(array $classMap) 
  36. if ($this->classMap) { 
  37. $this->classMap = array_merge($this->classMap, $classMap); 
  38. } else { 
  39. $this->classMap = $classMap; 
  40.  
  41. /** 
  42. * Registers a set of PSR-0 directories for a given prefix, either 
  43. * appending or prepending to the ones previously set for this prefix. 
  44. * @param string $prefix The prefix 
  45. * @param array|string $paths The PSR-0 root directories 
  46. * @param bool $prepend Whether to prepend the directories 
  47. */ 
  48. public function add($prefix, $paths, $prepend = false) 
  49. if (!$prefix) { 
  50. if ($prepend) { 
  51. $this->fallbackDirsPsr0 = array_merge( 
  52. (array) $paths,  
  53. $this->fallbackDirsPsr0 
  54. ); 
  55. } else { 
  56. $this->fallbackDirsPsr0 = array_merge( 
  57. $this->fallbackDirsPsr0,  
  58. (array) $paths 
  59. ); 
  60.  
  61. return; 
  62.  
  63. $first = $prefix[0]; 
  64. if (!isset($this->prefixesPsr0[$first][$prefix])) { 
  65. $this->prefixesPsr0[$first][$prefix] = (array) $paths; 
  66.  
  67. return; 
  68. if ($prepend) { 
  69. $this->prefixesPsr0[$first][$prefix] = array_merge( 
  70. (array) $paths,  
  71. $this->prefixesPsr0[$first][$prefix] 
  72. ); 
  73. } else { 
  74. $this->prefixesPsr0[$first][$prefix] = array_merge( 
  75. $this->prefixesPsr0[$first][$prefix],  
  76. (array) $paths 
  77. ); 
  78.  
  79. /** 
  80. * Registers a set of PSR-4 directories for a given namespace, either 
  81. * appending or prepending to the ones previously set for this namespace. 
  82. * @param string $prefix The prefix/namespace, with trailing '\\' 
  83. * @param array|string $paths The PSR-0 base directories 
  84. * @param bool $prepend Whether to prepend the directories 
  85. * @throws \InvalidArgumentException 
  86. */ 
  87. public function addPsr4($prefix, $paths, $prepend = false) 
  88. if (!$prefix) { 
  89. // Register directories for the root namespace. 
  90. if ($prepend) { 
  91. $this->fallbackDirsPsr4 = array_merge( 
  92. (array) $paths,  
  93. $this->fallbackDirsPsr4 
  94. ); 
  95. } else { 
  96. $this->fallbackDirsPsr4 = array_merge( 
  97. $this->fallbackDirsPsr4,  
  98. (array) $paths 
  99. ); 
  100. } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 
  101. // Register directories for a new namespace. 
  102. $length = strlen($prefix); 
  103. if ('\\' !== $prefix[$length - 1]) { 
  104. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 
  105. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 
  106. $this->prefixDirsPsr4[$prefix] = (array) $paths; 
  107. } elseif ($prepend) { 
  108. // Prepend directories for an already registered namespace. 
  109. $this->prefixDirsPsr4[$prefix] = array_merge( 
  110. (array) $paths,  
  111. $this->prefixDirsPsr4[$prefix] 
  112. ); 
  113. } else { 
  114. // Append directories for an already registered namespace. 
  115. $this->prefixDirsPsr4[$prefix] = array_merge( 
  116. $this->prefixDirsPsr4[$prefix],  
  117. (array) $paths 
  118. ); 
  119.  
  120. /** 
  121. * Registers a set of PSR-0 directories for a given prefix,  
  122. * replacing any others previously set for this prefix. 
  123. * @param string $prefix The prefix 
  124. * @param array|string $paths The PSR-0 base directories 
  125. */ 
  126. public function set($prefix, $paths) 
  127. if (!$prefix) { 
  128. $this->fallbackDirsPsr0 = (array) $paths; 
  129. } else { 
  130. $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 
  131.  
  132. /** 
  133. * Registers a set of PSR-4 directories for a given namespace,  
  134. * replacing any others previously set for this namespace. 
  135. * @param string $prefix The prefix/namespace, with trailing '\\' 
  136. * @param array|string $paths The PSR-4 base directories 
  137. * @throws \InvalidArgumentException 
  138. */ 
  139. public function setPsr4($prefix, $paths) 
  140. if (!$prefix) { 
  141. $this->fallbackDirsPsr4 = (array) $paths; 
  142. } else { 
  143. $length = strlen($prefix); 
  144. if ('\\' !== $prefix[$length - 1]) { 
  145. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 
  146. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 
  147. $this->prefixDirsPsr4[$prefix] = (array) $paths; 
  148.  
  149. /** 
  150. * Turns on searching the include path for class files. 
  151. * @param bool $useIncludePath 
  152. */ 
  153. public function setUseIncludePath($useIncludePath) 
  154. $this->useIncludePath = $useIncludePath; 
  155.  
  156. /** 
  157. * Can be used to check if the autoloader uses the include path to check 
  158. * for classes. 
  159. * @return bool 
  160. */ 
  161. public function getUseIncludePath() 
  162. return $this->useIncludePath; 
  163.  
  164. /** 
  165. * Registers this instance as an autoloader. 
  166. * @param bool $prepend Whether to prepend the autoloader or not 
  167. */ 
  168. public function register($prepend = false) 
  169. spl_autoload_register(array($this, 'loadClass'), true, $prepend); 
  170.  
  171. /** 
  172. * Unregisters this instance as an autoloader. 
  173. */ 
  174. public function unregister() 
  175. spl_autoload_unregister(array($this, 'loadClass')); 
  176.  
  177. /** 
  178. * Loads the given class or interface. 
  179. * @param string $class The name of the class 
  180. * @return bool|null True if loaded, null otherwise 
  181. */ 
  182. public function loadClass($class) 
  183. if ($file = $this->findFile($class)) { 
  184. includeFile($file); 
  185.  
  186. return true; 
  187.  
  188. /** 
  189. * Finds the path to the file where the class is defined. 
  190. * @param string $class The name of the class 
  191. * @return string|false The path if found, false otherwise 
  192. */ 
  193. public function findFile($class) 
  194. // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 
  195. if ('\\' == $class[0]) { 
  196. $class = substr($class, 1); 
  197.  
  198. // class map lookup 
  199. if (isset($this->classMap[$class])) { 
  200. return $this->classMap[$class]; 
  201.  
  202. $file = $this->findFileWithExtension($class, '.php'); 
  203.  
  204. // Search for Hack files if we are running on HHVM 
  205. if ($file === null && defined('HHVM_VERSION')) { 
  206. $file = $this->findFileWithExtension($class, '.hh'); 
  207.  
  208. if ($file === null) { 
  209. // Remember that this class does not exist. 
  210. return $this->classMap[$class] = false; 
  211.  
  212. return $file; 
  213.  
  214. private function findFileWithExtension($class, $ext) 
  215. // PSR-4 lookup 
  216. $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 
  217.  
  218. $first = $class[0]; 
  219. if (isset($this->prefixLengthsPsr4[$first])) { 
  220. foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { 
  221. if (0 === strpos($class, $prefix)) { 
  222. foreach ($this->prefixDirsPsr4[$prefix] as $dir) { 
  223. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { 
  224. return $file; 
  225.  
  226. // PSR-4 fallback dirs 
  227. foreach ($this->fallbackDirsPsr4 as $dir) { 
  228. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 
  229. return $file; 
  230.  
  231. // PSR-0 lookup 
  232. if (false !== $pos = strrpos($class, '\\')) { 
  233. // namespaced class name 
  234. $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 
  235. . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 
  236. } else { 
  237. // PEAR-like class name 
  238. $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 
  239.  
  240. if (isset($this->prefixesPsr0[$first])) { 
  241. foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 
  242. if (0 === strpos($class, $prefix)) { 
  243. foreach ($dirs as $dir) { 
  244. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 
  245. return $file; 
  246.  
  247. // PSR-0 fallback dirs 
  248. foreach ($this->fallbackDirsPsr0 as $dir) { 
  249. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 
  250. return $file; 
  251.  
  252. // PSR-0 include paths. 
  253. if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 
  254. return $file;