Ver Fonte

Fixes #91 - Inconsistent parameter names Zend_Cache_Backend_Static/Zend_Cache_Backend

Frank Brückner há 12 anos atrás
pai
commit
c04c3a6df3

+ 30 - 12
library/Zend/Cache/Backend/Static.php

@@ -47,16 +47,16 @@ class Zend_Cache_Backend_Static
      * @var array
      */
     protected $_options = array(
-        'public_dir'            => null,
-        'sub_dir'               => 'html',
-        'file_extension'        => '.html',
-        'index_filename'        => 'index',
-        'file_locking'          => true,
-        'cache_file_umask'      => 0600,
-        'cache_directory_umask' => 0700,
-        'debug_header'          => false,
-        'tag_cache'             => null,
-        'disable_caching'       => false
+        'public_dir'           => null,
+        'sub_dir'              => 'html',
+        'file_extension'       => '.html',
+        'index_filename'       => 'index',
+        'file_locking'         => true,
+        'cache_file_perm'      => 0600,
+        'cache_directory_perm' => 0700,
+        'debug_header'         => false,
+        'tag_cache'            => null,
+        'disable_caching'      => false
     );
 
     /**
@@ -85,6 +85,24 @@ class Zend_Cache_Backend_Static
         if ($name == 'tag_cache') {
             $this->setInnerCache($value);
         } else {
+            // See #ZF-12047 and #GH-91
+            if ($name == 'cache_file_umask') {
+                trigger_error(
+                    "'cache_file_umask' is deprecated -> please use 'cache_file_perm' instead",
+                    E_USER_NOTICE
+                );
+
+                $name = 'cache_file_perm';
+            }
+            if ($name == 'cache_directory_umask') {
+                trigger_error(
+                    "'cache_directory_umask' is deprecated -> please use 'cache_directory_perm' instead",
+                    E_USER_NOTICE
+                );
+
+                $name = 'cache_directory_perm';
+            }
+
             parent::setOption($name, $value);
         }
         return $this;
@@ -233,7 +251,7 @@ class Zend_Cache_Backend_Static
         } else {
             $result = file_put_contents($file, $data);
         }
-        @chmod($file, $this->_octdec($this->_options['cache_file_umask']));
+        @chmod($file, $this->_octdec($this->_options['cache_file_perm']));
 
         if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
             $this->_tagged = $tagged;
@@ -259,7 +277,7 @@ class Zend_Cache_Backend_Static
     {
         if (!is_dir($path)) {
             $oldUmask = umask(0);
-            if ( !@mkdir($path, $this->_octdec($this->_options['cache_directory_umask']), true)) {
+            if ( !@mkdir($path, $this->_octdec($this->_options['cache_directory_perm']), true)) {
                 $lastErr = error_get_last();
                 umask($oldUmask);
                 Zend_Cache::throwException("Can't create directory: {$lastErr['message']}");

+ 34 - 2
tests/Zend/Cache/StaticBackendTest.php

@@ -139,9 +139,9 @@ class Zend_Cache_StaticBackendTest extends Zend_Cache_CommonBackendTest {
         $this->assertEquals('content', $this->_instance->load(bin2hex('/0')));
     }
 
-    public function testDirectoryUmaskAsString()
+    public function testDirectoryPermAsString()
     {
-        $this->_instance->setOption('cache_directory_umask', '777');
+        $this->_instance->setOption('cache_directory_perm', '777');
 
         $res = $this->_instance->save('data to cache', bin2hex('/foo/bar'));
         $this->assertTrue($res);
@@ -153,6 +153,38 @@ class Zend_Cache_StaticBackendTest extends Zend_Cache_CommonBackendTest {
         rmdir($this->_instance->getOption('public_dir') . '/foo');
     }
 
+    /**
+     * @group GH-91
+     */
+    public function testDirectoryUmaskTriggersError()
+    {
+        try {
+            $this->_instance->setOption('cache_directory_umask', '777');
+            $this->fail();
+        } catch (PHPUnit_Framework_Error $e) {
+            $this->assertEquals(
+                "'cache_directory_umask' is deprecated -> please use 'cache_directory_perm' instead",
+                $e->getMessage()
+            );
+        }
+    }
+
+    /**
+     * @group GH-91
+     */
+    public function testFileUmaskTriggersError()
+    {
+        try {
+            $this->_instance->setOption('cache_file_umask', '777');
+            $this->fail();
+        } catch (PHPUnit_Framework_Error $e) {
+            $this->assertEquals(
+                "'cache_file_umask' is deprecated -> please use 'cache_file_perm' instead",
+                $e->getMessage()
+            );
+        }
+    }
+
     public function testSaveWithSpecificExtensionWithTag()
     {
         $res = $this->_instance->save(serialize(array('data to cache', 'xml')), bin2hex('/foo'), array('tag1'));