Array.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_Translate
  17. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @version $Id: $
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Locale */
  22. require_once 'Zend/Locale.php';
  23. /** Zend_Translate_Adapter */
  24. require_once 'Zend/Translate/Adapter.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Translate
  28. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Translate_Adapter_Array extends Zend_Translate_Adapter
  32. {
  33. private $_data = array();
  34. /**
  35. * Generates the adapter
  36. *
  37. * @param array $data Translation data
  38. * @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
  39. * see Zend_Locale for more information
  40. * @param array $options OPTIONAL Options to set
  41. */
  42. public function __construct($data, $locale = null, array $options = array())
  43. {
  44. parent::__construct($data, $locale, $options);
  45. }
  46. /**
  47. * Load translation data
  48. *
  49. * @param string|array $data
  50. * @param string $locale Locale/Language to add data for, identical with locale identifier,
  51. * see Zend_Locale for more information
  52. * @param array $options OPTIONAL Options to use
  53. * @return array
  54. */
  55. protected function _loadTranslationData($data, $locale, array $options = array())
  56. {
  57. $this->_data = array();
  58. if (!is_array($data)) {
  59. if (file_exists($data)) {
  60. ob_start();
  61. $data = include($data);
  62. ob_end_clean();
  63. }
  64. }
  65. if (!is_array($data)) {
  66. require_once 'Zend/Translate/Exception.php';
  67. throw new Zend_Translate_Exception("Error including array or file '".$data."'");
  68. }
  69. if (!isset($this->_data[$locale])) {
  70. $this->_data[$locale] = array();
  71. }
  72. $this->_data[$locale] = $data + $this->_data[$locale];
  73. return $this->_data;
  74. }
  75. /**
  76. * returns the adapters name
  77. *
  78. * @return string
  79. */
  80. public function toString()
  81. {
  82. return "Array";
  83. }
  84. }