@@ -108,9 +108,9 @@ private function getClassCandidates($class)
108
108
}
109
109
110
110
if ($ function [0 ] instanceof ComposerClassLoader || $ function [0 ] instanceof SymfonyClassLoader) {
111
- foreach ($ function [0 ]->getPrefixes () as $ paths ) {
111
+ foreach ($ function [0 ]->getPrefixes () as $ prefix => $ paths ) {
112
112
foreach ($ paths as $ path ) {
113
- $ classes = array_merge ($ classes , $ this ->findClassInPath ($ path , $ class ));
113
+ $ classes = array_merge ($ classes , $ this ->findClassInPath ($ path , $ class, $ prefix ));
114
114
}
115
115
}
116
116
}
@@ -122,10 +122,11 @@ private function getClassCandidates($class)
122
122
/**
123
123
* @param string $path
124
124
* @param string $class
125
+ * @param string $prefix
125
126
*
126
127
* @return array
127
128
*/
128
- private function findClassInPath ($ path , $ class )
129
+ private function findClassInPath ($ path , $ class, $ prefix )
129
130
{
130
131
if (!$ path = realpath ($ path )) {
131
132
return array ();
@@ -134,7 +135,7 @@ private function findClassInPath($path, $class)
134
135
$ classes = array ();
135
136
$ filename = $ class .'.php ' ;
136
137
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 )) {
138
139
$ classes [] = $ class ;
139
140
}
140
141
}
@@ -145,27 +146,38 @@ private function findClassInPath($path, $class)
145
146
/**
146
147
* @param string $path
147
148
* @param string $file
149
+ * @param string $prefix
148
150
*
149
151
* @return string|null
150
152
*/
151
- private function convertFileToClass ($ path , $ file )
10000
153
+ private function convertFileToClass ($ path , $ file, $ prefix )
152
154
{
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
+ );
155
165
156
166
// We cannot use the autoloader here as most of them use require; but if the class
157
167
// is not found, the new autoloader call will require the file again leading to a
158
168
// "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
+ }
161
173
}
162
174
163
- if ($ this ->classExists ($ namespacedClass )) {
164
- return $ namespacedClass ;
165
- }
175
+ require_once $ file ;
166
176
167
- if ($ this ->classExists ($ pearClass )) {
168
- return $ pearClass ;
177
+ foreach ($ candidates as $ candidate ) {
178
+ if ($ this ->classExists ($ candidate )) {
179
+ return $ candidate ;
180
+ }
169
181
}
170
182
}
171
183
0 commit comments