Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
9 * file that was distributed with this source code. | 9 * file that was distributed with this source code. |
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\Debug\FatalErrorHandler; | 12 namespace Symfony\Component\Debug\FatalErrorHandler; |
13 | 13 |
14 use Composer\Autoload\ClassLoader as ComposerClassLoader; | |
15 use Symfony\Component\ClassLoader\ClassLoader as SymfonyClassLoader; | |
16 use Symfony\Component\Debug\DebugClassLoader; | |
14 use Symfony\Component\Debug\Exception\ClassNotFoundException; | 17 use Symfony\Component\Debug\Exception\ClassNotFoundException; |
15 use Symfony\Component\Debug\Exception\FatalErrorException; | 18 use Symfony\Component\Debug\Exception\FatalErrorException; |
16 use Symfony\Component\Debug\DebugClassLoader; | |
17 use Composer\Autoload\ClassLoader as ComposerClassLoader; | |
18 use Symfony\Component\ClassLoader\ClassLoader as SymfonyClassLoader; | |
19 | 19 |
20 /** | 20 /** |
21 * ErrorHandler for classes that do not exist. | 21 * ErrorHandler for classes that do not exist. |
22 * | 22 * |
23 * @author Fabien Potencier <fabien@symfony.com> | 23 * @author Fabien Potencier <fabien@symfony.com> |
27 /** | 27 /** |
28 * {@inheritdoc} | 28 * {@inheritdoc} |
29 */ | 29 */ |
30 public function handleError(array $error, FatalErrorException $exception) | 30 public function handleError(array $error, FatalErrorException $exception) |
31 { | 31 { |
32 $messageLen = strlen($error['message']); | 32 $messageLen = \strlen($error['message']); |
33 $notFoundSuffix = '\' not found'; | 33 $notFoundSuffix = '\' not found'; |
34 $notFoundSuffixLen = strlen($notFoundSuffix); | 34 $notFoundSuffixLen = \strlen($notFoundSuffix); |
35 if ($notFoundSuffixLen > $messageLen) { | 35 if ($notFoundSuffixLen > $messageLen) { |
36 return; | 36 return; |
37 } | 37 } |
38 | 38 |
39 if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) { | 39 if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) { |
40 return; | 40 return; |
41 } | 41 } |
42 | 42 |
43 foreach (array('class', 'interface', 'trait') as $typeName) { | 43 foreach (['class', 'interface', 'trait'] as $typeName) { |
44 $prefix = ucfirst($typeName).' \''; | 44 $prefix = ucfirst($typeName).' \''; |
45 $prefixLen = strlen($prefix); | 45 $prefixLen = \strlen($prefix); |
46 if (0 !== strpos($error['message'], $prefix)) { | 46 if (0 !== strpos($error['message'], $prefix)) { |
47 continue; | 47 continue; |
48 } | 48 } |
49 | 49 |
50 $fullyQualifiedClassName = substr($error['message'], $prefixLen, -$notFoundSuffixLen); | 50 $fullyQualifiedClassName = substr($error['message'], $prefixLen, -$notFoundSuffixLen); |
83 * | 83 * |
84 * @return array An array of possible fully qualified class names | 84 * @return array An array of possible fully qualified class names |
85 */ | 85 */ |
86 private function getClassCandidates($class) | 86 private function getClassCandidates($class) |
87 { | 87 { |
88 if (!is_array($functions = spl_autoload_functions())) { | 88 if (!\is_array($functions = spl_autoload_functions())) { |
89 return array(); | 89 return []; |
90 } | 90 } |
91 | 91 |
92 // find Symfony and Composer autoloaders | 92 // find Symfony and Composer autoloaders |
93 $classes = array(); | 93 $classes = []; |
94 | 94 |
95 foreach ($functions as $function) { | 95 foreach ($functions as $function) { |
96 if (!is_array($function)) { | 96 if (!\is_array($function)) { |
97 continue; | 97 continue; |
98 } | 98 } |
99 // get class loaders wrapped by DebugClassLoader | 99 // get class loaders wrapped by DebugClassLoader |
100 if ($function[0] instanceof DebugClassLoader) { | 100 if ($function[0] instanceof DebugClassLoader) { |
101 $function = $function[0]->getClassLoader(); | 101 $function = $function[0]->getClassLoader(); |
102 | 102 |
103 if (!is_array($function)) { | 103 if (!\is_array($function)) { |
104 continue; | 104 continue; |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 if ($function[0] instanceof ComposerClassLoader || $function[0] instanceof SymfonyClassLoader) { | 108 if ($function[0] instanceof ComposerClassLoader || $function[0] instanceof SymfonyClassLoader) { |
131 * | 131 * |
132 * @return array | 132 * @return array |
133 */ | 133 */ |
134 private function findClassInPath($path, $class, $prefix) | 134 private function findClassInPath($path, $class, $prefix) |
135 { | 135 { |
136 if (!$path = realpath($path.'/'.strtr($prefix, '\\_', '//')) ?: realpath($path.'/'.dirname(strtr($prefix, '\\_', '//'))) ?: realpath($path)) { | 136 if (!$path = realpath($path.'/'.strtr($prefix, '\\_', '//')) ?: realpath($path.'/'.\dirname(strtr($prefix, '\\_', '//'))) ?: realpath($path)) { |
137 return array(); | 137 return []; |
138 } | 138 } |
139 | 139 |
140 $classes = array(); | 140 $classes = []; |
141 $filename = $class.'.php'; | 141 $filename = $class.'.php'; |
142 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { | 142 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { |
143 if ($filename == $file->getFileName() && $class = $this->convertFileToClass($path, $file->getPathName(), $prefix)) { | 143 if ($filename == $file->getFileName() && $class = $this->convertFileToClass($path, $file->getPathName(), $prefix)) { |
144 $classes[] = $class; | 144 $classes[] = $class; |
145 } | 145 } |
155 * | 155 * |
156 * @return string|null | 156 * @return string|null |
157 */ | 157 */ |
158 private function convertFileToClass($path, $file, $prefix) | 158 private function convertFileToClass($path, $file, $prefix) |
159 { | 159 { |
160 $candidates = array( | 160 $candidates = [ |
161 // namespaced class | 161 // namespaced class |
162 $namespacedClass = str_replace(array($path.DIRECTORY_SEPARATOR, '.php', '/'), array('', '', '\\'), $file), | 162 $namespacedClass = str_replace([$path.\DIRECTORY_SEPARATOR, '.php', '/'], ['', '', '\\'], $file), |
163 // namespaced class (with target dir) | 163 // namespaced class (with target dir) |
164 $prefix.$namespacedClass, | 164 $prefix.$namespacedClass, |
165 // namespaced class (with target dir and separator) | 165 // namespaced class (with target dir and separator) |
166 $prefix.'\\'.$namespacedClass, | 166 $prefix.'\\'.$namespacedClass, |
167 // PEAR class | 167 // PEAR class |
168 str_replace('\\', '_', $namespacedClass), | 168 str_replace('\\', '_', $namespacedClass), |
169 // PEAR class (with target dir) | 169 // PEAR class (with target dir) |
170 str_replace('\\', '_', $prefix.$namespacedClass), | 170 str_replace('\\', '_', $prefix.$namespacedClass), |
171 // PEAR class (with target dir and separator) | 171 // PEAR class (with target dir and separator) |
172 str_replace('\\', '_', $prefix.'\\'.$namespacedClass), | 172 str_replace('\\', '_', $prefix.'\\'.$namespacedClass), |
173 ); | 173 ]; |
174 | 174 |
175 if ($prefix) { | 175 if ($prefix) { |
176 $candidates = array_filter($candidates, function ($candidate) use ($prefix) { return 0 === strpos($candidate, $prefix); }); | 176 $candidates = array_filter($candidates, function ($candidate) use ($prefix) { return 0 === strpos($candidate, $prefix); }); |
177 } | 177 } |
178 | 178 |