Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/class-loader/Psr4ClassLoader.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
| author | Chris Cannam |
|---|---|
| date | Thu, 28 Feb 2019 13:21:36 +0000 |
| parents | 1fec387a4317 |
| children |
comparison
equal
deleted
inserted
replaced
| 16:c2387f117808 | 17:129ea1e6d783 |
|---|---|
| 22 * | 22 * |
| 23 * @deprecated since version 3.3, to be removed in 4.0. | 23 * @deprecated since version 3.3, to be removed in 4.0. |
| 24 */ | 24 */ |
| 25 class Psr4ClassLoader | 25 class Psr4ClassLoader |
| 26 { | 26 { |
| 27 private $prefixes = array(); | 27 private $prefixes = []; |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * @param string $prefix | 30 * @param string $prefix |
| 31 * @param string $baseDir | 31 * @param string $baseDir |
| 32 */ | 32 */ |
| 33 public function addPrefix($prefix, $baseDir) | 33 public function addPrefix($prefix, $baseDir) |
| 34 { | 34 { |
| 35 $prefix = trim($prefix, '\\').'\\'; | 35 $prefix = trim($prefix, '\\').'\\'; |
| 36 $baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; | 36 $baseDir = rtrim($baseDir, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR; |
| 37 $this->prefixes[] = array($prefix, $baseDir); | 37 $this->prefixes[] = [$prefix, $baseDir]; |
| 38 } | 38 } |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * @param string $class | 41 * @param string $class |
| 42 * | 42 * |
| 46 { | 46 { |
| 47 $class = ltrim($class, '\\'); | 47 $class = ltrim($class, '\\'); |
| 48 | 48 |
| 49 foreach ($this->prefixes as list($currentPrefix, $currentBaseDir)) { | 49 foreach ($this->prefixes as list($currentPrefix, $currentBaseDir)) { |
| 50 if (0 === strpos($class, $currentPrefix)) { | 50 if (0 === strpos($class, $currentPrefix)) { |
| 51 $classWithoutPrefix = substr($class, strlen($currentPrefix)); | 51 $classWithoutPrefix = substr($class, \strlen($currentPrefix)); |
| 52 $file = $currentBaseDir.str_replace('\\', DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php'; | 52 $file = $currentBaseDir.str_replace('\\', \DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php'; |
| 53 if (file_exists($file)) { | 53 if (file_exists($file)) { |
| 54 return $file; | 54 return $file; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 } | 57 } |
| 79 * | 79 * |
| 80 * @param bool $prepend | 80 * @param bool $prepend |
| 81 */ | 81 */ |
| 82 public function register($prepend = false) | 82 public function register($prepend = false) |
| 83 { | 83 { |
| 84 spl_autoload_register(array($this, 'loadClass'), true, $prepend); | 84 spl_autoload_register([$this, 'loadClass'], true, $prepend); |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Removes this instance from the registered autoloaders. | 88 * Removes this instance from the registered autoloaders. |
| 89 */ | 89 */ |
| 90 public function unregister() | 90 public function unregister() |
| 91 { | 91 { |
| 92 spl_autoload_unregister(array($this, 'loadClass')); | 92 spl_autoload_unregister([$this, 'loadClass']); |
| 93 } | 93 } |
| 94 } | 94 } |
