Cache.php

Go to the documentation of this file.
00001 <?php
00002 
00034 class Robo47_Application_Resource_Cache
00035 extends Zend_Application_Resource_ResourceAbstract
00036 {
00037 
00042     protected $_cache = array();
00043     
00044     public function init()
00045     {
00046         if (!empty($this->_options)) {
00047             $this->_cache = $this->_setupCache($this->_options);
00048         } else {
00049             $message = 'Empty options in resource ' .
00050                 'Robo47_Application_Resource_Cache.';
00051             throw new Robo47_Application_Resource_Exception($message);
00052         }
00053     }
00054 
00060     public function _setupCache($config)
00061     {
00062         if (!isset($config['frontendName'])) {
00063             $message = 'Cache config doesn\'t contain frontendName';
00064             throw new Robo47_Application_Resource_Exception($message);
00065         }
00066 
00067         if (!isset($config['backendName'])) {
00068             $message = 'Cache config doesn\'t contain backendName';
00069             throw new Robo47_Application_Resource_Exception($message);
00070         }
00071 
00072         if (!isset($config['frontendOptions'])) {
00073             $config['frontendOptions'] = array();
00074         }
00075 
00076         if (!isset($config['backendOptions'])) {
00077             $config['backendOptions'] = array();
00078         }
00079 
00080         if (!isset($config['customFrontendNaming'])) {
00081             $config['customFrontendNaming'] = false;
00082         }
00083 
00084         if (!isset($config['customBackendNaming'])) {
00085             $config['customBackendNaming'] = false;
00086         }
00087 
00088         if (!isset($config['autoload'])) {
00089             $config['autoload'] = false;
00090         }
00091 
00092         $cache = Zend_Cache::factory(
00093             $config['frontendName'],
00094             $config['backendName'],
00095             $config['frontendOptions'],
00096             $config['backendOptions'],
00097             $config['customFrontendNaming'],
00098             $config['customBackendNaming'],
00099             $config['autoload']
00100         );
00101 
00102         if (isset($config['registryKey'])) {
00103             Zend_Registry::set($config['registryKey'], $cache);
00104         }
00105         return $cache;
00106     }
00107 
00113     public function getCache()
00114     {
00115         return $this->_cache;
00116     }
00117 }