Explorar el Código

merged from trunk: ZF-9793: added missing method "getOption()" to cache backends

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@24989 44c647ce-9c0f-0410-b52a-842ac1e357ba
mabe hace 13 años
padre
commit
9edb4566b5

+ 22 - 0
library/Zend/Cache/Backend.php

@@ -112,6 +112,28 @@ class Zend_Cache_Backend
     }
 
     /**
+     * Returns an option
+     *
+     * @param string $name Optional, the options name to return
+     * @throws Zend_Cache_Exceptions
+     * @return mixed
+     */
+    public function getOption($name)
+    {
+        $name = strtolower($name);
+
+        if (array_key_exists($name, $this->_options)) {
+            return $this->_options[$name];
+        }
+
+        if (array_key_exists($name, $this->_directives)) {
+            return $this->_directives[$name];
+        }
+
+        Zend_Cache::throwException("Incorrect option name : {$name}");
+    }
+
+    /**
      * Get the life time
      *
      * if $specificLifetime is not false, the given specific life time is used

+ 4 - 8
library/Zend/Cache/Backend/Static.php

@@ -99,17 +99,13 @@ class Zend_Cache_Backend_Static
      */
     public function getOption($name)
     {
+        $name = strtolower($name);
+
         if ($name == 'tag_cache') {
             return $this->getInnerCache();
-        } else {
-            if (in_array($name, $this->_options)) {
-                return $this->_options[$name];
-            }
-            if ($name == 'lifetime') {
-                return parent::getLifetime();
-            }
-            return null;
         }
+
+        return parent::getOption($name);
     }
 
     /**

+ 11 - 10
library/Zend/Cache/Core.php

@@ -235,17 +235,18 @@ class Zend_Cache_Core
      */
     public function getOption($name)
     {
-        if (is_string($name)) {
-            $name = strtolower($name);
-            if (array_key_exists($name, $this->_options)) {
-                // This is a Core option
-                return $this->_options[$name];
-            }
-            if (array_key_exists($name, $this->_specificOptions)) {
-                // This a specic option of this frontend
-                return $this->_specificOptions[$name];
-            }
+        $name = strtolower($name);
+
+        if (array_key_exists($name, $this->_options)) {
+            // This is a Core option
+            return $this->_options[$name];
         }
+
+        if (array_key_exists($name, $this->_specificOptions)) {
+            // This a specic option of this frontend
+            return $this->_specificOptions[$name];
+        }
+
         Zend_Cache::throwException("Incorrect option name : $name");
     }
 

+ 7 - 2
tests/Zend/Cache/CommonBackendTest.php

@@ -280,6 +280,11 @@ abstract class Zend_Cache_CommonBackendTest extends PHPUnit_Framework_TestCase {
         $this->assertFalse($this->_instance->test('bar3'));
     }
 
-}
-
+    public function testGetOption()
+    {
+        $this->assertTrue(is_numeric($this->_instance->getOption('LifeTime')));
 
+        $this->setExpectedException('Zend_Cache_Exception');
+        $this->_instance->getOption('unknown');
+    }
+}

+ 0 - 1
tests/Zend/Cache/FileFrontendTest.php

@@ -231,5 +231,4 @@ class Zend_Cache_FileFrontendTest extends PHPUnit_Framework_TestCase {
         $this->assertEquals(2, count($this->_instance3->getOption('master_files')));
         $this->assertNotNull($this->_instance3->getOption('master_file'));
     }
-
 }