PageRenderTime 58ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/kz40_site/www/wp/wp-content/plugins/backup-by-supsystic/modules/amazon/aws/Symfony/Component/ClassLoader/ClassLoader.php

https://gitlab.com/megathrone86/SoftwareProjects
PHP | 199 lines | 91 code | 19 blank | 89 comment | 11 complexity | b78827cc88a851bbf1b56f6168985afe MD5 | raw file
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\ClassLoader;
  11. /**
  12. * ClassLoader implements an PSR-0 class loader
  13. *
  14. * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
  15. *
  16. * $loader = new ClassLoader();
  17. *
  18. * // register classes with namespaces
  19. * $loader->addPrefix('Symfony\Component', __DIR__.'/component');
  20. * $loader->addPrefix('Symfony', __DIR__.'/framework');
  21. *
  22. * // activate the autoloader
  23. * $loader->register();
  24. *
  25. * // to enable searching the include path (e.g. for PEAR packages)
  26. * $loader->setUseIncludePath(true);
  27. *
  28. * In this example, if you try to use a class in the Symfony\Component
  29. * namespace or one of its children (Symfony\Component\Console for instance),
  30. * the autoloader will first look for the class under the component/
  31. * directory, and it will then fallback to the framework/ directory if not
  32. * found before giving up.
  33. *
  34. * @author Fabien Potencier <fabien@symfony.com>
  35. * @author Jordi Boggiano <j.boggiano@seld.be>
  36. */
  37. class ClassLoader
  38. {
  39. private $prefixes = array();
  40. private $fallbackDirs = array();
  41. private $useIncludePath = false;
  42. /**
  43. * Returns prefixes.
  44. *
  45. * @return array
  46. */
  47. public function getPrefixes()
  48. {
  49. return $this->prefixes;
  50. }
  51. /**
  52. * Returns fallback directories.
  53. *
  54. * @return array
  55. */
  56. public function getFallbackDirs()
  57. {
  58. return $this->fallbackDirs;
  59. }
  60. /**
  61. * Adds prefixes.
  62. *
  63. * @param array $prefixes Prefixes to add
  64. */
  65. public function addPrefixes(array $prefixes)
  66. {
  67. foreach ($prefixes as $prefix => $path) {
  68. $this->addPrefix($prefix, $path);
  69. }
  70. }
  71. /**
  72. * Registers a set of classes
  73. *
  74. * @param string $prefix The classes prefix
  75. * @param array|string $paths The location(s) of the classes
  76. */
  77. public function addPrefix($prefix, $paths)
  78. {
  79. if (!$prefix) {
  80. foreach ((array) $paths as $path) {
  81. $this->fallbackDirs[] = $path;
  82. }
  83. return;
  84. }
  85. if (isset($this->prefixes[$prefix])) {
  86. $this->prefixes[$prefix] = array_merge(
  87. $this->prefixes[$prefix],
  88. (array) $paths
  89. );
  90. } else {
  91. $this->prefixes[$prefix] = (array) $paths;
  92. }
  93. }
  94. /**
  95. * Turns on searching the include for class files.
  96. *
  97. * @param Boolean $useIncludePath
  98. */
  99. public function setUseIncludePath($useIncludePath)
  100. {
  101. $this->useIncludePath = $useIncludePath;
  102. }
  103. /**
  104. * Can be used to check if the autoloader uses the include path to check
  105. * for classes.
  106. *
  107. * @return Boolean
  108. */
  109. public function getUseIncludePath()
  110. {
  111. return $this->useIncludePath;
  112. }
  113. /**
  114. * Registers this instance as an autoloader.
  115. *
  116. * @param Boolean $prepend Whether to prepend the autoloader or not
  117. */
  118. public function register($prepend = false)
  119. {
  120. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  121. }
  122. /**
  123. * Unregisters this instance as an autoloader.
  124. */
  125. public function unregister()
  126. {
  127. spl_autoload_unregister(array($this, 'loadClass'));
  128. }
  129. /**
  130. * Loads the given class or interface.
  131. *
  132. * @param string $class The name of the class
  133. *
  134. * @return Boolean|null True, if loaded
  135. */
  136. public function loadClass($class)
  137. {
  138. if ($file = $this->findFile($class)) {
  139. require $file;
  140. return true;
  141. }
  142. }
  143. /**
  144. * Finds the path to the file where the class is defined.
  145. *
  146. * @param string $class The name of the class
  147. *
  148. * @return string|null The path, if found
  149. */
  150. public function findFile($class)
  151. {
  152. if (false !== $pos = strrpos($class, '\\')) {
  153. // namespaced class name
  154. $classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)).DIRECTORY_SEPARATOR;
  155. $className = substr($class, $pos + 1);
  156. } else {
  157. // PEAR-like class name
  158. $classPath = null;
  159. $className = $class;
  160. }
  161. $classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
  162. foreach ($this->prefixes as $prefix => $dirs) {
  163. if ($class === strstr($class, $prefix)) {
  164. foreach ($dirs as $dir) {
  165. if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
  166. return $dir.DIRECTORY_SEPARATOR.$classPath;
  167. }
  168. }
  169. }
  170. }
  171. foreach ($this->fallbackDirs as $dir) {
  172. if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
  173. return $dir.DIRECTORY_SEPARATOR.$classPath;
  174. }
  175. }
  176. if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) {
  177. return $file;
  178. }
  179. }
  180. }