Procházet zdrojové kódy

ZF-10220: added method Zend_Cache_Manager::getCaches

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22727 44c647ce-9c0f-0410-b52a-842ac1e357ba
mabe před 15 roky
rodič
revize
c909d43e1c
2 změnil soubory, kde provedl 38 přidání a 14 odebrání
  1. 26 14
      library/Zend/Cache/Manager.php
  2. 12 0
      tests/Zend/Cache/ManagerTest.php

+ 26 - 14
library/Zend/Cache/Manager.php

@@ -57,17 +57,6 @@ class Zend_Cache_Manager
      * @var array
      */
     protected $_optionTemplates = array(
-        // Null Cache (Enforce Null/Empty Values)
-        'skeleton' => array(
-            'frontend' => array(
-                'name'    => null,
-                'options' => array(),
-            ),
-            'backend' => array(
-                'name'    => null,
-                'options' => array(),
-            ),
-        ),
         // Simple Common Default
         'default' => array(
             'frontend' => array(
@@ -79,10 +68,12 @@ class Zend_Cache_Manager
             'backend' => array(
                 'name'    => 'File',
                 'options' => array(
-                    'cache_dir' => '../cache',
+                    // use system temp dir by default of file backend
+                    // 'cache_dir' => '../cache',
                 ),
             ),
         ),
+
         // Static Page HTML Cache
         'page' => array(
             'frontend' => array(
@@ -98,6 +89,7 @@ class Zend_Cache_Manager
                 ),
             ),
         ),
+
         // Tag Cache
         'pagetag' => array(
             'frontend' => array(
@@ -110,8 +102,10 @@ class Zend_Cache_Manager
             'backend' => array(
                 'name'    => 'File',
                 'options' => array(
-                    'cache_dir' => '../cache',
-                    'cache_file_umask' => 0644
+                    // use system temp dir by default of file backend
+                    // 'cache_dir' => '../cache',
+                    // use default umask of file backend
+                    // 'cache_file_umask' => 0644
                 ),
             ),
         ),
@@ -167,6 +161,7 @@ class Zend_Cache_Manager
                 $this->_optionTemplates[$name]['backend']['options']['tag_cache']
                     = $this->getCache(self::PAGETAGCACHE);
             }
+
             $this->_caches[$name] = Zend_Cache::factory(
                 $this->_optionTemplates[$name]['frontend']['name'],
                 $this->_optionTemplates[$name]['backend']['name'],
@@ -176,11 +171,28 @@ class Zend_Cache_Manager
                 isset($this->_optionTemplates[$name]['backend']['customBackendNaming']) ? $this->_optionTemplates[$name]['backend']['customBackendNaming'] : false,
                 isset($this->_optionTemplates[$name]['frontendBackendAutoload']) ? $this->_optionTemplates[$name]['frontendBackendAutoload'] : false
             );
+
             return $this->_caches[$name];
         }
     }
 
     /**
+     * Fetch all available caches
+     *
+     * @return array An array of all available caches with it's names as key
+     */
+    public function getCaches()
+    {
+        $caches = $this->_caches;
+        foreach ($this->_optionTemplates as $name => $tmp) {
+            if (!isset($caches[$name])) {
+                $caches[$name] = $this->getCache($name);
+            }
+        }
+        return $caches;
+    }
+
+    /**
      * Set a named configuration template from which a cache object can later
      * be lazy loaded
      *

+ 12 - 0
tests/Zend/Cache/ManagerTest.php

@@ -55,6 +55,18 @@ class Zend_Cache_ManagerTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($manager->getCache('cache1') instanceof Zend_Cache_Core);
     }
 
+    /**
+     * @group ZF-10220
+     */
+    public function testGetAvialableCaches()
+    {
+        $manager = new Zend_Cache_Manager();
+        $caches  = $manager->getCaches();
+
+        $this->assertType('array', $caches);
+        $this->assertArrayHasKey('default', $caches);
+    }
+
     public function testLazyLoadsDefaultPageCache()
     {
         $manager = new Zend_Cache_Manager;