web/lib/Zend/Application/Resource/Locale.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Application
    16  * @package    Zend_Application
    17  * @subpackage Resource
    17  * @subpackage Resource
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Locale.php 20814 2010-02-01 20:13:08Z freak $
    20  * @version    $Id: Locale.php 24593 2012-01-05 20:35:02Z matthew $
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * @see Zend_Application_Resource_ResourceAbstract
    24  * @see Zend_Application_Resource_ResourceAbstract
    25  */
    25  */
    31  *
    31  *
    32  * @uses       Zend_Application_Resource_Base
    32  * @uses       Zend_Application_Resource_Base
    33  * @category   Zend
    33  * @category   Zend
    34  * @package    Zend_Application
    34  * @package    Zend_Application
    35  * @subpackage Resource
    35  * @subpackage Resource
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    36  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    38  */
    38  */
    39 class Zend_Application_Resource_Locale
    39 class Zend_Application_Resource_Locale
    40     extends Zend_Application_Resource_ResourceAbstract
    40     extends Zend_Application_Resource_ResourceAbstract
    41 {
    41 {
    54     public function init()
    54     public function init()
    55     {
    55     {
    56         return $this->getLocale();
    56         return $this->getLocale();
    57     }
    57     }
    58 
    58 
    59 
       
    60     /**
    59     /**
    61      * Retrieve locale object
    60      * Retrieve locale object
    62      *
    61      *
    63      * @return Zend_Locale
    62      * @return Zend_Locale
    64      */
    63      */
    65     public function getLocale()
    64     public function getLocale()
    66     {
    65     {
    67         if (null === $this->_locale) {
    66         if (null === $this->_locale) {
    68             $options = $this->getOptions();
    67             $options = $this->getOptions();
    69             if(!isset($options['default'])) {
    68 
       
    69             if (!isset($options['default'])) {
    70                 $this->_locale = new Zend_Locale();
    70                 $this->_locale = new Zend_Locale();
    71             } elseif(!isset($options['force']) ||
    71             } elseif(!isset($options['force']) ||
    72                      (bool) $options['force'] == false)
    72                      (bool) $options['force'] == false)
    73             {
    73             {
    74                 // Don't force any locale, just go for auto detection
    74                 // Don't force any locale, just go for auto detection
    84             Zend_Registry::set($key, $this->_locale);
    84             Zend_Registry::set($key, $this->_locale);
    85         }
    85         }
    86 
    86 
    87         return $this->_locale;
    87         return $this->_locale;
    88     }
    88     }
       
    89 
       
    90     /**
       
    91      * Set the cache
       
    92      *
       
    93      * @param string|Zend_Cache_Core $cache
       
    94      * @return Zend_Application_Resource_Locale
       
    95      */
       
    96     public function setCache($cache)
       
    97     {
       
    98         if (is_string($cache)) {
       
    99             $bootstrap = $this->getBootstrap();
       
   100             if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper
       
   101                 && $bootstrap->hasPluginResource('CacheManager')
       
   102             ) {
       
   103                 $cacheManager = $bootstrap->bootstrap('CacheManager')
       
   104                     ->getResource('CacheManager');
       
   105                 if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
       
   106                     $cache = $cacheManager->getCache($cache);
       
   107                 }
       
   108             }
       
   109         }
       
   110 
       
   111         if ($cache instanceof Zend_Cache_Core) {
       
   112             Zend_Locale::setCache($cache);
       
   113         }
       
   114 
       
   115         return $this;
       
   116     }
    89 }
   117 }