Locale.php 2.5 KB

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