Frank Brückner пре 12 година
родитељ
комит
f096717f5c
2 измењених фајлова са 41 додато и 31 уклоњено
  1. 32 23
      library/Zend/Cache/Frontend/Class.php
  2. 9 8
      tests/Zend/Cache/ClassFrontendTest.php

+ 32 - 23
library/Zend/Cache/Frontend/Class.php

@@ -30,7 +30,7 @@ require_once 'Zend/Cache/Core.php';
  * @package    Zend_Cache
  * @subpackage Zend_Cache_Frontend
  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @license    http://framework.zend.com/license/new-bsd New BSD License
  */
 class Zend_Cache_Frontend_Class extends Zend_Cache_Core
 {
@@ -53,9 +53,9 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
      * @var array available options
      */
     protected $_specificOptions = array(
-        'cached_entity' => null,
-        'cache_by_default' => true,
-        'cached_methods' => array(),
+        'cached_entity'      => null,
+        'cache_by_default'   => true,
+        'cached_methods'     => array(),
         'non_cached_methods' => array()
     );
 
@@ -64,23 +64,23 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
      *
      * @var array
      */
-    private $_tags = array();
+    protected $_tags = array();
 
     /**
      * SpecificLifetime value
      *
      * false => no specific life time
      *
-     * @var int
+     * @var bool|int
      */
-    private $_specificLifetime = false;
+    protected $_specificLifetime = false;
 
     /**
      * The cached object or the name of the cached abstract class
      *
      * @var mixed
      */
-    private $_cachedEntity = null;
+    protected $_cachedEntity = null;
 
      /**
       * The class name of the cached object or cached abstract class
@@ -89,21 +89,20 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
       *
       * @var string
       */
-    private $_cachedEntityLabel = '';
+    protected $_cachedEntityLabel = '';
 
     /**
      * Priority (used by some particular backends)
      *
      * @var int
      */
-    private $_priority = 8;
+    protected $_priority = 8;
 
     /**
      * Constructor
      *
      * @param  array $options Associative array of options
      * @throws Zend_Cache_Exception
-     * @return void
      */
     public function __construct(array $options = array())
     {
@@ -120,7 +119,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
     /**
      * Set a specific life time
      *
-     * @param  int $specificLifetime
+     * @param  bool|int $specificLifetime
      * @return void
      */
     public function setSpecificLifetime($specificLifetime = false)
@@ -168,11 +167,15 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
     public function setCachedEntity($cachedEntity)
     {
         if (!is_string($cachedEntity) && !is_object($cachedEntity)) {
-            Zend_Cache::throwException('cached_entity must be an object or a class name');
+            Zend_Cache::throwException(
+                'cached_entity must be an object or a class name'
+            );
         }
-        $this->_cachedEntity = $cachedEntity;
+
+        $this->_cachedEntity                     = $cachedEntity;
         $this->_specificOptions['cached_entity'] = $cachedEntity;
-        if (is_string($this->_cachedEntity)){
+
+        if (is_string($this->_cachedEntity)) {
             $this->_cachedEntityLabel = $this->_cachedEntity;
         } else {
             $ro = new ReflectionObject($this->_cachedEntity);
@@ -197,6 +200,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
      * @param  string $name       Method name
      * @param  array  $parameters Method parameters
      * @return mixed Result
+     * @throws Exception
      */
     public function __call($name, $parameters)
     {
@@ -209,15 +213,17 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
         $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));
+        $cache      = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
+
         if (!$cache) {
             // We do not have not cache
             return call_user_func_array($callback, $parameters);
         }
 
-        $id = $this->_makeId($name, $parameters);
-        if ( ($rs = $this->load($id)) && (array_key_exists(0, $rs)) 
-                                      && (array_key_exists(1, $rs)) ) {
+        $id = $this->makeId($name, $parameters);
+        if (($rs = $this->load($id)) && (array_key_exists(0, $rs))
+            && (array_key_exists(1, $rs))
+        ) {
             // A cache is available
             $output = $rs[0];
             $return = $rs[1];
@@ -229,8 +235,12 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
             try {
                 $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);
+                $data   = array($output, $return);
+
+                $this->save(
+                    $data, $id, $this->_tags, $this->_specificLifetime,
+                    $this->_priority
+                );
             } catch (Exception $e) {
                 ob_end_clean();
                 throw $e;
@@ -262,5 +272,4 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
     {
         return md5($this->_cachedEntityLabel . '__' . $name . '__' . serialize($args));
     }
-
-}
+}

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

@@ -37,8 +37,8 @@ require_once 'Zend/Cache/Backend/Test.php';
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  * @group      Zend_Cache
  */
-class test {
-
+class test
+{
     private $_string = 'hello !';
 
     public static function foobar($param1, $param2)
@@ -78,8 +78,8 @@ class test {
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  * @group      Zend_Cache
  */
-class Zend_Cache_ClassFrontendTest extends PHPUnit_Framework_TestCase {
-
+class Zend_Cache_ClassFrontendTest extends PHPUnit_Framework_TestCase
+{
     private $_instance1;
     private $_instance2;
 
@@ -228,6 +228,9 @@ class Zend_Cache_ClassFrontendTest extends PHPUnit_Framework_TestCase {
         $this->assertEquals('foobar_output(param1, param2)', $data);
     }
 
+    /**
+     * @group GH-125
+     */
     public function testCallCorrectCall8()
     {
         $this->_instance2->setOption('cache_by_default', true);
@@ -239,7 +242,7 @@ class Zend_Cache_ClassFrontendTest extends PHPUnit_Framework_TestCase {
         ob_implicit_flush(true);
 
         $this->assertNull($return);
-        $this->assertEquals('foobar_output(param1,param2)',$data);
+        $this->assertEquals('foobar_output(param1,param2)', $data);
       
     }
 
@@ -295,6 +298,4 @@ class Zend_Cache_ClassFrontendTest extends PHPUnit_Framework_TestCase {
         $this->setExpectedException('Zend_Cache_Exception');
         $this->_instance2->unknownMethod();
     }
-
-}
-
+}