web/enmi/Zend/Application/Resource/Locale.php
changeset 19 1c2f13fd785c
parent 0 4eba9c11703f
equal deleted inserted replaced
18:bd595ad770fc 19:1c2f13fd785c
       
     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-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    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 $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Application_Resource_ResourceAbstract
       
    25  */
       
    26 require_once 'Zend/Application/Resource/ResourceAbstract.php';
       
    27 
       
    28 
       
    29 /**
       
    30  * Resource for initializing the locale
       
    31  *
       
    32  * @uses       Zend_Application_Resource_Base
       
    33  * @category   Zend
       
    34  * @package    Zend_Application
       
    35  * @subpackage Resource
       
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    38  */
       
    39 class Zend_Application_Resource_Locale
       
    40     extends Zend_Application_Resource_ResourceAbstract
       
    41 {
       
    42     const DEFAULT_REGISTRY_KEY = 'Zend_Locale';
       
    43 
       
    44     /**
       
    45      * @var Zend_Locale
       
    46      */
       
    47     protected $_locale;
       
    48 
       
    49     /**
       
    50      * Defined by Zend_Application_Resource_Resource
       
    51      *
       
    52      * @return Zend_Locale
       
    53      */
       
    54     public function init()
       
    55     {
       
    56         return $this->getLocale();
       
    57     }
       
    58 
       
    59 
       
    60     /**
       
    61      * Retrieve locale object
       
    62      *
       
    63      * @return Zend_Locale
       
    64      */
       
    65     public function getLocale()
       
    66     {
       
    67         if (null === $this->_locale) {
       
    68             $options = $this->getOptions();
       
    69             if(!isset($options['default'])) {
       
    70                 $this->_locale = new Zend_Locale();
       
    71             } elseif(!isset($options['force']) ||
       
    72                      (bool) $options['force'] == false)
       
    73             {
       
    74                 // Don't force any locale, just go for auto detection
       
    75                 Zend_Locale::setDefault($options['default']);
       
    76                 $this->_locale = new Zend_Locale();
       
    77             } else {
       
    78                 $this->_locale = new Zend_Locale($options['default']);
       
    79             }
       
    80 
       
    81             $key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
       
    82                 ? $options['registry_key']
       
    83                 : self::DEFAULT_REGISTRY_KEY;
       
    84             Zend_Registry::set($key, $this->_locale);
       
    85         }
       
    86 
       
    87         return $this->_locale;
       
    88     }
       
    89 }