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 /**
0024  * @see Zend_Application_Resource_ResourceAbstract
0025  */
0026 // require_once 'Zend/Application/Resource/ResourceAbstract.php';
0027 
0028 
0029 /**
0030  * Resource for initializing the locale
0031  *
0032  * @uses       Zend_Application_Resource_Base
0033  * @category   Zend
0034  * @package    Zend_Application
0035  * @subpackage Resource
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Application_Resource_Locale
0040     extends Zend_Application_Resource_ResourceAbstract
0041 {
0042     const DEFAULT_REGISTRY_KEY = 'Zend_Locale';
0043 
0044     /**
0045      * @var Zend_Locale
0046      */
0047     protected $_locale;
0048 
0049     /**
0050      * Defined by Zend_Application_Resource_Resource
0051      *
0052      * @return Zend_Locale
0053      */
0054     public function init()
0055     {
0056         return $this->getLocale();
0057     }
0058 
0059     /**
0060      * Retrieve locale object
0061      *
0062      * @return Zend_Locale
0063      */
0064     public function getLocale()
0065     {
0066         if (null === $this->_locale) {
0067             $options = $this->getOptions();
0068 
0069             if (!isset($options['default'])) {
0070                 $this->_locale = new Zend_Locale();
0071             } elseif (!isset($options['force'])
0072                       || (bool)$options['force'] == false
0073             ) {
0074                 // Don't force any locale, just go for auto detection
0075                 Zend_Locale::setDefault($options['default']);
0076                 $this->_locale = new Zend_Locale();
0077             } else {
0078                 $this->_locale = new Zend_Locale($options['default']);
0079             }
0080 
0081             $key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
0082                 ? $options['registry_key']
0083                 : self::DEFAULT_REGISTRY_KEY;
0084             Zend_Registry::set($key, $this->_locale);
0085         }
0086 
0087         return $this->_locale;
0088     }
0089 
0090     /**
0091      * Set the cache
0092      *
0093      * @param string|Zend_Cache_Core $cache
0094      * @return Zend_Application_Resource_Locale
0095      */
0096     public function setCache($cache)
0097     {
0098         if (is_string($cache)) {
0099             $bootstrap = $this->getBootstrap();
0100             if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper
0101                 && $bootstrap->hasPluginResource('CacheManager')
0102             ) {
0103                 $cacheManager = $bootstrap->bootstrap('CacheManager')
0104                     ->getResource('CacheManager');
0105                 if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
0106                     $cache = $cacheManager->getCache($cache);
0107                 }
0108             }
0109         }
0110 
0111         if ($cache instanceof Zend_Cache_Core) {
0112             Zend_Locale::setCache($cache);
0113         }
0114 
0115         return $this;
0116     }
0117 }