Quellcode durchsuchen

Switched from array parameter to serialized parameter when saving static cache data

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20694 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic vor 16 Jahren
Ursprung
Commit
6e2591a827

+ 17 - 1
library/Zend/Cache/Backend/Static.php

@@ -203,10 +203,12 @@ class Zend_Cache_Backend_Static
             return true;
         }
         $extension = null;
-        if (is_array($data)) {
+        if ($this->_isSerialized($data)) {
+            $data = unserialize($data);
             $extension = '.' . ltrim($data[1], '.');
             $data = $data[0];
         }
+        
         clearstatcache();
         if (is_null($id) || strlen($id) == 0) {
             $id = $this->_detectId();
@@ -264,6 +266,20 @@ class Zend_Cache_Backend_Static
             }
         }
     }
+    
+    /**
+     * Detect serialization of data (cannot predict since this is the only way
+     * to obey the interface yet pass in another parameter).
+     *
+     * In future, ZF 2.0, check if we can just avoid the interface restraints.
+     *
+     * This format is the only valid one possible for the class, so it's simple
+     * to just run a regular expression for the starting serialized format.
+     */
+    protected function _isSerialized($data)
+    {
+        return preg_match("/a:2:\{i:0;s:\d+:\"/", $data);
+    }
 
     /**
      * Remove a cache record

+ 1 - 0
library/Zend/Cache/Manager.php

@@ -86,6 +86,7 @@ class Zend_Cache_Manager
                 'name'    => 'Capture',
                 'options' => array(
                     'ignore_user_abort' => true,
+                    'automatic_serialization' => true
                 ),
             ),
             'backend' => array(

+ 6 - 6
tests/Zend/Cache/StaticBackendTest.php

@@ -120,24 +120,24 @@ class Zend_Cache_StaticBackendTest extends Zend_Cache_CommonBackendTest {
     
     public function testSaveWithSpecificExtension()
     {
-        $res = $this->_instance->save(array('data to cache', 'xml'), bin2hex('/foo2'));
+        $res = $this->_instance->save(serialize(array('data to cache', 'xml')), bin2hex('/foo2'));
         $this->assertTrue($this->_instance->test(bin2hex('/foo2')));
         unlink($this->_instance->getOption('public_dir') . '/foo2.xml');
     }
 
     public function testSaveWithSpecificExtensionWithTag()
     {
-        $res = $this->_instance->save(array('data to cache', 'xml'), bin2hex('/foo'), array('tag1'));
+        $res = $this->_instance->save(serialize(array('data to cache', 'xml')), bin2hex('/foo'), array('tag1'));
         $this->assertTrue($this->_instance->test(bin2hex('/foo')));
         unlink($this->_instance->getOption('public_dir') . '/foo.xml');
     }
     
     public function testRemovalWithSpecificExtension()
     {
-        $res = $this->_instance->save(array('data to cache', 'xml'), bin2hex('/foo'), array('tag1'));
-        $this->assertTrue($this->_instance->test(bin2hex('/foo')));
-        $this->assertTrue($this->_instance->remove('/foo'));
-        $this->assertFalse($this->_instance->test(bin2hex('/foo')));
+        $res = $this->_instance->save(serialize(array('data to cache', 'xml')), bin2hex('/foo3'), array('tag1'));
+        $this->assertTrue($this->_instance->test(bin2hex('/foo3')));
+        $this->assertTrue($this->_instance->remove('/foo3'));
+        $this->assertFalse($this->_instance->test(bin2hex('/foo3')));
     }
 
     public function testTestWithAnExistingCacheId()