8000 [Debug] fixed class lookup when using PSR-0 with a target dir · src-run/symfony@f5b38ec · GitHub
[go: up one dir, main page]

Skip to content

Commit f5b38ec

Browse files
committed
[Debug] fixed class lookup when using PSR-0 with a target dir
1 parent 3a1661b commit f5b38ec

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ private function getClassCandidates($class)
108108
}
109109

110110
if ($function[0] instanceof ComposerClassLoader || $function[0] instanceof SymfonyClassLoader) {
111-
foreach ($function[0]->getPrefixes() as $paths) {
111+
foreach ($function[0]->getPrefixes() as $prefix => $paths) {
112112
foreach ($paths as $path) {
113-
$classes = array_merge($classes, $this->findClassInPath($path, $class));
113+
$classes = array_merge($classes, $this->findClassInPath($path, $class, $prefix));
114114
}
115115
}
116116
}
@@ -122,10 +122,11 @@ private function getClassCandidates($class)
122122
/**
123123
* @param string $path
124124
* @param string $class
125+
* @param string $prefix
125126
*
126127
* @return array
127128
*/
128-
private function findClassInPath($path, $class)
129+
private function findClassInPath($path, $class, $prefix)
129130
{
130131
if (!$path = realpath($path)) {
131132
return array();
@@ -134,7 +135,7 @@ private function findClassInPath($path, $class)
134135
$classes = array();
135136
$filename = $class.'.php';
136137
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
137-
if ($filename == $file->getFileName() && $class = $this->convertFileToClass($path, $file->getPathName())) {
138+
if ($filename == $file->getFileName() && $class = $this->convertFileToClass($path, $file->getPathName(), $prefix)) {
138139
$classes[] = $class;
139140
}
140141
}
@@ -145,27 +146,38 @@ private function findClassInPath($path, $class)
145146
/**
146147
* @param string $path
147148
* @param string $file
149+
* @param string $prefix
148150
*
149151
* @return string|null
150152
*/
151-
private function convertFileToClass($path, $file) 10000
153+
private function convertFileToClass($path, $file, $prefix)
152154
{
153-
$namespacedClass = str_replace(array($path.DIRECTORY_SEPARATOR, '.php', '/'), array('', '', '\\'), $file);
154-
$pearClass = str_replace('\\', '_', $namespacedClass);
155+
$candidates = array(
156+
// namespaced class
157+
$namespacedClass = str_replace(array($path.DIRECTORY_SEPARATOR, '.php', '/'), array('', '', '\\'), $file),
158+
// namespaced class (with target dir)
159+
$namespacedClassTargetDir = $prefix.str_replace(array($path.DIRECTORY_SEPARATOR, '.php', '/'), array('', '', '\\'), $file),
160+
// PEAR class
161+
str_replace('\\', '_', $namespacedClass),
162+
// PEAR class (with target dir)
163+
str_replace('\\', '_', $namespacedClassTargetDir),
164+
);
155165

156166
// We cannot use the autoloader here as most of them use require; but if the class
157167
// is not found, the new autoloader call will require the file again leading to a
158168
// "cannot redeclare class" error.
159-
if (!$this->classExists($namespacedClass) && !$this->classExists($pearClass)) {
160-
require_once $file;
169+
foreach ($candidates as $candidate) {
170+
if ($this->classExists($candidate)) {
171+
return $candidate;
172+
}
161173
}
162174

163-
if ($this->classExists($namespacedClass)) {
164-
return $namespacedClass;
165-
}
175+
require_once $file;
166176

167-
if ($this->classExists($pearClass)) {
168-
return $pearClass;
177+
foreach ($candidates as $candidate) {
178+
if ($this->classExists($candidate)) {
179+
return $candidate;
180+
}
169181
}
170182
}
171183

0 commit comments

Comments
 (0)
0