@@ -164,15 +164,16 @@ public function getByType($class)
164164 return $ this ->currentService ;
165165 }
166166
167- $ lower = ltrim (strtolower ($ class ), '\\' );
168- if (!isset ($ this ->classes [$ lower ][TRUE ])) {
167+ $ class = ltrim ($ class , '\\' );
168+ if (!isset ($ this ->classes [$ class ][TRUE ])) {
169+ self ::checkCase ($ class );
169170 return ;
170171
171- } elseif (count ($ this ->classes [$ lower ][TRUE ]) === 1 ) {
172- return $ this ->classes [$ lower ][TRUE ][0 ];
172+ } elseif (count ($ this ->classes [$ class ][TRUE ]) === 1 ) {
173+ return $ this ->classes [$ class ][TRUE ][0 ];
173174
174175 } else {
175- throw new ServiceCreationException ("Multiple services of type $ class found: " . implode (', ' , $ this ->classes [$ lower ][TRUE ]));
176+ throw new ServiceCreationException ("Multiple services of type $ class found: " . implode (', ' , $ this ->classes [$ class ][TRUE ]));
176177 }
177178 }
178179
@@ -184,7 +185,8 @@ public function getByType($class)
184185 */
185186 public function findByType ($ class , $ autowired = TRUE )
186187 {
187- $ class = ltrim (strtolower ($ class ), '\\' );
188+ $ class = ltrim ($ class , '\\' );
189+ self ::checkCase ($ class );
188190 return array_merge (
189191 isset ($ this ->classes [$ class ][TRUE ]) ? $ this ->classes [$ class ][TRUE ] : array (),
190192 !$ autowired && isset ($ this ->classes [$ class ][FALSE ]) ? $ this ->classes [$ class ][FALSE ] : array ()
@@ -282,14 +284,14 @@ public function prepareClassList()
282284 // build auto-wiring list
283285 $ excludedClasses = array ();
284286 foreach ($ this ->excludedClasses as $ class ) {
285- $ excludedClasses += array_change_key_case (class_parents ($ class ) + class_implements ($ class ) + array ($ class => $ class ));
287+ self ::checkCase ($ class );
288+ $ excludedClasses += class_parents ($ class ) + class_implements ($ class ) + array ($ class => $ class );
286289 }
287290
288291 $ this ->classes = array ();
289292 foreach ($ this ->definitions as $ name => $ def ) {
290293 if ($ class = $ def ->getImplement () ?: $ def ->getClass ()) {
291294 foreach (class_parents ($ class ) + class_implements ($ class ) + array ($ class ) as $ parent ) {
292- $ parent = strtolower ($ parent );
293295 $ this ->classes [$ parent ][$ def ->isAutowired () && empty ($ excludedClasses [$ parent ])][] = (string ) $ name ;
294296 }
295297 }
@@ -303,16 +305,16 @@ public function prepareClassList()
303305
304306 private function resolveImplement (ServiceDefinition $ def , $ name )
305307 {
306- $ implement = $ def ->getImplement ();
307- if (!interface_exists ($ implement )) {
308- throw new ServiceCreationException ("Interface $ implement used in service ' $ name' not found. " );
308+ $ interface = $ def ->getImplement ();
309+ if (!interface_exists ($ interface )) {
310+ throw new ServiceCreationException ("Interface $ interface used in service ' $ name' not found. " );
309311 }
310- $ rc = Reflection \ClassType::from ($ implement );
312+ self ::checkCase ($ interface );
313+ $ rc = Reflection \ClassType::from ($ interface );
311314 $ method = $ rc ->hasMethod ('create ' ) ? $ rc ->getMethod ('create ' ) : ($ rc ->hasMethod ('get ' ) ? $ rc ->getMethod ('get ' ) : NULL );
312315 if (count ($ rc ->getMethods ()) !== 1 || !$ method || $ method ->isStatic ()) {
313- throw new ServiceCreationException ("Interface $ implement used in service ' $ name' must have just one non-static method create() or get(). " );
316+ throw new ServiceCreationException ("Interface $ interface used in service ' $ name' must have just one non-static method create() or get(). " );
314317 }
315- $ def ->setImplement ($ rc ->getName ());
316318 $ def ->setImplementType ($ rc ->hasMethod ('create ' ) ? 'create ' : 'get ' );
317319
318320 if (!$ def ->getClass () && !$ def ->getEntity ()) {
@@ -386,7 +388,7 @@ private function resolveServiceClass($name, $recursive = array())
386388 if (!class_exists ($ class ) && !interface_exists ($ class )) {
387389 throw new ServiceCreationException ("Class or interface $ class used in service ' $ name' not found. " );
388390 }
389- $ def -> setClass ( Reflection \ClassType:: from ($ class)-> getName () );
391+ self :: checkCase ($ class );
390392
391393 } elseif ($ def ->isAutowired ()) {
392394 trigger_error ("Type of service ' $ name' is unknown. " , E_USER_NOTICE );
@@ -424,14 +426,14 @@ private function resolveEntityClass($entity, $recursive = array())
424426 }
425427
426428 $ class = preg_replace ('#[|\s].*# ' , '' , $ reflection ->getAnnotation ('return ' ));
427- if ($ class && $ refClass ) {
428- $ class = Reflection \AnnotationsParser::expandClassName ($ class , $ refClass );
429+ if ($ class ) {
430+ $ class = $ refClass ? Reflection \AnnotationsParser::expandClassName ($ class , $ refClass) : ltrim ( $ class , '\\' );
429431 }
430432 return $ class ;
431433
432434 } elseif ($ service = $ this ->getServiceName ($ entity )) { // alias or factory
433435 if (Strings::contains ($ service , '\\' )) { // @\Class
434- return $ service ;
436+ return ltrim ( $ service, '\\' ) ;
435437 }
436438 return $ this ->definitions [$ service ]->getImplement () ?: $ this ->resolveServiceClass ($ service , $ recursive );
437439
@@ -440,7 +442,15 @@ private function resolveEntityClass($entity, $recursive = array())
440442 $ name = array_slice (array_keys ($ recursive ), -1 );
441443 throw new ServiceCreationException ("Class $ entity used in service ' $ name [0 ]' not found or is not instantiable. " );
442444 }
443- return $ entity ;
445+ return ltrim ($ entity , '\\' );
446+ }
447+ }
448+
449+
450+ private function checkCase ($ class )
451+ {
452+ if (class_exists ($ class ) && ($ rc = new \ReflectionClass ($ class )) && $ class !== $ rc ->getName ()) {
453+ throw new ServiceCreationException ("Case mismatch on class name ' $ class', correct name is ' {$ rc ->getName ()}'. " );
444454 }
445455 }
446456
0 commit comments