PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/user/plugins/email/vendor/composer/ClassLoader.php

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