Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/class-loader/ClassLoader.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 |
---|---|
41 * | 41 * |
42 * @deprecated since version 3.3, to be removed in 4.0. | 42 * @deprecated since version 3.3, to be removed in 4.0. |
43 */ | 43 */ |
44 class ClassLoader | 44 class ClassLoader |
45 { | 45 { |
46 private $prefixes = array(); | 46 private $prefixes = []; |
47 private $fallbackDirs = array(); | 47 private $fallbackDirs = []; |
48 private $useIncludePath = false; | 48 private $useIncludePath = false; |
49 | 49 |
50 /** | 50 /** |
51 * Returns prefixes. | 51 * Returns prefixes. |
52 * | 52 * |
93 } | 93 } |
94 | 94 |
95 return; | 95 return; |
96 } | 96 } |
97 if (isset($this->prefixes[$prefix])) { | 97 if (isset($this->prefixes[$prefix])) { |
98 if (is_array($paths)) { | 98 if (\is_array($paths)) { |
99 $this->prefixes[$prefix] = array_unique(array_merge( | 99 $this->prefixes[$prefix] = array_unique(array_merge( |
100 $this->prefixes[$prefix], | 100 $this->prefixes[$prefix], |
101 $paths | 101 $paths |
102 )); | 102 )); |
103 } elseif (!in_array($paths, $this->prefixes[$prefix])) { | 103 } elseif (!\in_array($paths, $this->prefixes[$prefix])) { |
104 $this->prefixes[$prefix][] = $paths; | 104 $this->prefixes[$prefix][] = $paths; |
105 } | 105 } |
106 } else { | 106 } else { |
107 $this->prefixes[$prefix] = array_unique((array) $paths); | 107 $this->prefixes[$prefix] = array_unique((array) $paths); |
108 } | 108 } |
134 * | 134 * |
135 * @param bool $prepend Whether to prepend the autoloader or not | 135 * @param bool $prepend Whether to prepend the autoloader or not |
136 */ | 136 */ |
137 public function register($prepend = false) | 137 public function register($prepend = false) |
138 { | 138 { |
139 spl_autoload_register(array($this, 'loadClass'), true, $prepend); | 139 spl_autoload_register([$this, 'loadClass'], true, $prepend); |
140 } | 140 } |
141 | 141 |
142 /** | 142 /** |
143 * Unregisters this instance as an autoloader. | 143 * Unregisters this instance as an autoloader. |
144 */ | 144 */ |
145 public function unregister() | 145 public function unregister() |
146 { | 146 { |
147 spl_autoload_unregister(array($this, 'loadClass')); | 147 spl_autoload_unregister([$this, 'loadClass']); |
148 } | 148 } |
149 | 149 |
150 /** | 150 /** |
151 * Loads the given class or interface. | 151 * Loads the given class or interface. |
152 * | 152 * |
172 */ | 172 */ |
173 public function findFile($class) | 173 public function findFile($class) |
174 { | 174 { |
175 if (false !== $pos = strrpos($class, '\\')) { | 175 if (false !== $pos = strrpos($class, '\\')) { |
176 // namespaced class name | 176 // namespaced class name |
177 $classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)).DIRECTORY_SEPARATOR; | 177 $classPath = str_replace('\\', \DIRECTORY_SEPARATOR, substr($class, 0, $pos)).\DIRECTORY_SEPARATOR; |
178 $className = substr($class, $pos + 1); | 178 $className = substr($class, $pos + 1); |
179 } else { | 179 } else { |
180 // PEAR-like class name | 180 // PEAR-like class name |
181 $classPath = null; | 181 $classPath = null; |
182 $className = $class; | 182 $className = $class; |
183 } | 183 } |
184 | 184 |
185 $classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php'; | 185 $classPath .= str_replace('_', \DIRECTORY_SEPARATOR, $className).'.php'; |
186 | 186 |
187 foreach ($this->prefixes as $prefix => $dirs) { | 187 foreach ($this->prefixes as $prefix => $dirs) { |
188 if ($class === strstr($class, $prefix)) { | 188 if ($class === strstr($class, $prefix)) { |
189 foreach ($dirs as $dir) { | 189 foreach ($dirs as $dir) { |
190 if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) { | 190 if (file_exists($dir.\DIRECTORY_SEPARATOR.$classPath)) { |
191 return $dir.DIRECTORY_SEPARATOR.$classPath; | 191 return $dir.\DIRECTORY_SEPARATOR.$classPath; |
192 } | 192 } |
193 } | 193 } |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 foreach ($this->fallbackDirs as $dir) { | 197 foreach ($this->fallbackDirs as $dir) { |
198 if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) { | 198 if (file_exists($dir.\DIRECTORY_SEPARATOR.$classPath)) { |
199 return $dir.DIRECTORY_SEPARATOR.$classPath; | 199 return $dir.\DIRECTORY_SEPARATOR.$classPath; |
200 } | 200 } |
201 } | 201 } |
202 | 202 |
203 if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) { | 203 if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) { |
204 return $file; | 204 return $file; |