Bläddra i källkod

merged branch Yrwein/class_loader_trait_exists (PR #2257)

Commits
-------

85ed5c6 [ClassLoader] Fixed state when trait_exists doesn't exists

Discussion
----------

[ClassLoader] Fixed state when trait_exists doesn't exists

Just for consistency of throwing exceptions in the ClassCollectionLoader. (An exception would be thrown in the next step by the ReflectionClass.)
Fabien Potencier 13 år sedan
förälder
incheckning
0bd1f15923

+ 1 - 1
src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

@@ -84,7 +84,7 @@ class ClassCollectionLoader
         $files = array();
         $content = '';
         foreach ($classes as $class) {
-            if (!class_exists($class) && !interface_exists($class) && function_exists('trait_exists') && !trait_exists($class)) {
+            if (!class_exists($class) && !interface_exists($class) && (!function_exists('trait_exists') || !trait_exists($class))) {
                 throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
             }
 

+ 1 - 1
src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php

@@ -54,7 +54,7 @@ class DebugUniversalClassLoader extends UniversalClassLoader
         if ($file = $this->findFile($class)) {
             require $file;
 
-            if (!class_exists($class, false) && !interface_exists($class, false) && function_exists('trait_exists') && !trait_exists($class)) {
+            if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class))) {
                 throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
             }
         }

+ 8 - 0
tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php

@@ -63,4 +63,12 @@ EOF;
 
         $this->assertEquals($expected, ClassCollectionLoader::fixNamespaceDeclarations($source));
     }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    public function testUnableToLoadClassException()
+    {
+        ClassCollectionLoader::load(array('SomeNotExistingClass'), '', 'foo', false);
+    }
 }