File indexing completed on 2024-12-22 05:36:28

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Application
0017  * @subpackage Resource
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 // require_once 'Zend/Application/Resource/ResourceAbstract.php';
0024 
0025 /**
0026  * Cache Manager resource
0027  *
0028  * @category   Zend
0029  * @package    Zend_Application
0030  * @subpackage Resource
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Application_Resource_Cachemanager extends Zend_Application_Resource_ResourceAbstract
0035 {
0036     /**
0037      * @var Zend_Cache_Manager
0038      */
0039     protected $_manager = null;
0040 
0041     /**
0042      * Initialize Cache_Manager
0043      *
0044      * @return Zend_Cache_Manager
0045      */
0046     public function init()
0047     {
0048         return $this->getCacheManager();
0049     }
0050 
0051     /**
0052      * Retrieve Zend_Cache_Manager instance
0053      *
0054      * @return Zend_Cache_Manager
0055      */
0056     public function getCacheManager()
0057     {
0058         if (null === $this->_manager) {
0059             $this->_manager = new Zend_Cache_Manager;
0060 
0061             $options = $this->getOptions();
0062             foreach ($options as $key => $value) {
0063                 // Logger
0064                 if (isset($value['frontend']['options']['logger'])) {
0065                     $logger = $value['frontend']['options']['logger'];
0066                     if (is_array($logger)) {
0067                         $value['frontend']['options']['logger'] = Zend_Log::factory($logger);
0068                     }
0069                 }
0070 
0071                 // Cache templates
0072                 if ($this->_manager->hasCacheTemplate($key)) {
0073                     $this->_manager->setTemplateOptions($key, $value);
0074                 } else {
0075                     $this->_manager->setCacheTemplate($key, $value);
0076                 }
0077             }
0078         }
0079 
0080         return $this->_manager;
0081     }
0082 }