소스 검색

ZF-11337: class cache should throw an exception on invalid method calls

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24031 44c647ce-9c0f-0410-b52a-842ac1e357ba
mabe 14 년 전
부모
커밋
a6990f42bd
2개의 변경된 파일17개의 추가작업 그리고 2개의 파일을 삭제
  1. 8 2
      library/Zend/Cache/Frontend/Class.php
  2. 9 0
      tests/Zend/Cache/ClassFrontendTest.php

+ 8 - 2
library/Zend/Cache/Frontend/Class.php

@@ -200,13 +200,19 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
      */
     public function __call($name, $parameters)
     {
+        $callback = array($this->_cachedEntity, $name);
+
+        if (!is_callable($callback, false)) {
+            Zend_Cache::throwException('Invalid callback');
+        }
+
         $cacheBool1 = $this->_specificOptions['cache_by_default'];
         $cacheBool2 = in_array($name, $this->_specificOptions['cached_methods']);
         $cacheBool3 = in_array($name, $this->_specificOptions['non_cached_methods']);
         $cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
         if (!$cache) {
             // We do not have not cache
-            return call_user_func_array(array($this->_cachedEntity, $name), $parameters);
+            return call_user_func_array($callback, $parameters);
         }
 
         $id = $this->_makeId($name, $parameters);
@@ -220,7 +226,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
             ob_implicit_flush(false);
 
             try {
-                $return = call_user_func_array(array($this->_cachedEntity, $name), $parameters);
+                $return = call_user_func_array($callback, $parameters);
                 $output = ob_get_clean();
                 $data = array($output, $return);
                 $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority);

+ 9 - 0
tests/Zend/Cache/ClassFrontendTest.php

@@ -264,5 +264,14 @@ class Zend_Cache_ClassFrontendTest extends PHPUnit_Framework_TestCase {
         $this->assertEquals('startend', $output);
     }
 
+    /**
+     * @group ZF-11337
+     */
+    public function testThrowExceptionOnInvalidCallback()
+    {
+        $this->setExpectedException('Zend_Cache_Exception');
+        $this->_instance2->unknownMethod();
+    }
+
 }