Procházet zdrojové kódy

ZF-8364: fixed wrong return value check for autoloader

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19187 44c647ce-9c0f-0410-b52a-842ac1e357ba
bate před 16 roky
rodič
revize
62aaeccaa7

+ 12 - 2
library/Zend/Loader/Autoloader/Resource.php

@@ -173,7 +173,13 @@ class Zend_Loader_Autoloader_Resource implements Zend_Loader_Autoloader_Interfac
 
         $final = substr($class, strlen($lastMatch) + 1);
         $path = $this->_components[$lastMatch];
-        return $path . '/' . str_replace('_', '/', $final) . '.php';
+        $classPath = $path . '/' . str_replace('_', '/', $final) . '.php';
+
+        if (Zend_Loader::isReadable($classPath)) {
+            return $classPath;
+        }
+
+        return false;
     }
 
     /**
@@ -184,7 +190,11 @@ class Zend_Loader_Autoloader_Resource implements Zend_Loader_Autoloader_Interfac
      */
     public function autoload($class)
     {
-        return include $this->getClassPath($class);
+        $classPath = $this->getClassPath($class);
+        if (false !== $classPath) {
+            return include $path;
+        }
+        return false;
     }
 
     /**

+ 13 - 1
tests/Zend/Loader/Autoloader/ResourceTest.php

@@ -404,7 +404,6 @@ class Zend_Loader_Autoloader_ResourceTest extends PHPUnit_Framework_TestCase
      */
     public function testAutoloaderResourceGetClassPath()
     {
-        //print_r(get_class_methods($this->loader));
         $this->loader->addResourceTypes(array(
             'model' => array('path' => 'models', 'namespace' => 'Model'),
         ));
@@ -412,6 +411,19 @@ class Zend_Loader_Autoloader_ResourceTest extends PHPUnit_Framework_TestCase
         // if true we have // in path
         $this->assertFalse(strpos($path, '//'));
     }
+
+    /**
+     * @group ZF-8364
+     * @group ZF-6727
+     */
+    public function testAuloaderResourceGetClassPathReturnFalse()
+    {
+        $this->loader->addResourceTypes(array(
+            'model' => array('path' => 'models', 'namespace' => 'Model'),
+        ));
+        $path = $this->loader->autoload('Something_Totally_Wrong');
+        $this->assertFalse($path);
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Loader_Autoloader_ResourceTest::main') {