Cachemanager.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Application
  17. * @subpackage Resource
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Application/Resource/ResourceAbstract.php';
  23. /**
  24. * Cache Manager resource
  25. *
  26. * @category Zend
  27. * @package Zend_Application
  28. * @subpackage Resource
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Application_Resource_Cachemanager extends Zend_Application_Resource_ResourceAbstract
  33. {
  34. /**
  35. * @var Zend_Cache_Manager
  36. */
  37. protected $_manager = null;
  38. /**
  39. * Initialize Cache_Manager
  40. *
  41. * @return Zend_Cache_Manager
  42. */
  43. public function init()
  44. {
  45. return $this->getCacheManager();
  46. }
  47. /**
  48. * Retrieve Zend_Cache_Manager instance
  49. *
  50. * @return Zend_Cache_Manager
  51. */
  52. public function getCacheManager()
  53. {
  54. if (null === $this->_manager) {
  55. $this->_manager = new Zend_Cache_Manager;
  56. $options = $this->getOptions();
  57. foreach ($options as $key => $value) {
  58. // Logger
  59. if (isset($value['frontend']['options']['logger'])) {
  60. $logger = $value['frontend']['options']['logger'];
  61. if (is_array($logger)) {
  62. $value['frontend']['options']['logger'] = Zend_Log::factory($logger);
  63. }
  64. }
  65. // Cache templates
  66. if ($this->_manager->hasCacheTemplate($key)) {
  67. $this->_manager->setTemplateOptions($key, $value);
  68. } else {
  69. $this->_manager->setCacheTemplate($key, $value);
  70. }
  71. }
  72. }
  73. return $this->_manager;
  74. }
  75. }