ArrayAccessibleResourceBundle.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Intl\ResourceBundle\Util;
  11. use Symfony\Component\Intl\Exception\BadMethodCallException;
  12. /**
  13. * Work-around for a bug in PHP's \ResourceBundle implementation.
  14. *
  15. * More information can be found on https://bugs.php.net/bug.php?id=64356.
  16. * This class can be removed once that bug is fixed.
  17. *
  18. * @author Bernhard Schussek <bschussek@gmail.com>
  19. */
  20. class ArrayAccessibleResourceBundle implements \ArrayAccess, \IteratorAggregate, \Countable
  21. {
  22. private $bundleImpl;
  23. public function __construct(\ResourceBundle $bundleImpl)
  24. {
  25. $this->bundleImpl = $bundleImpl;
  26. }
  27. public function get($offset, $fallback = null)
  28. {
  29. $value = $this->bundleImpl->get($offset, $fallback);
  30. return $value instanceof \ResourceBundle ? new static($value) : $value;
  31. }
  32. public function offsetExists($offset)
  33. {
  34. return null !== $this->bundleImpl[$offset];
  35. }
  36. public function offsetGet($offset)
  37. {
  38. return $this->get($offset);
  39. }
  40. public function offsetSet($offset, $value)
  41. {
  42. throw new BadMethodCallException('Resource bundles cannot be modified.');
  43. }
  44. public function offsetUnset($offset)
  45. {
  46. throw new BadMethodCallException('Resource bundles cannot be modified.');
  47. }
  48. public function getIterator()
  49. {
  50. return $this->bundleImpl;
  51. }
  52. public function count()
  53. {
  54. return $this->bundleImpl->count();
  55. }
  56. public function getErrorCode()
  57. {
  58. return $this->bundleImpl->getErrorCode();
  59. }
  60. public function getErrorMessage()
  61. {
  62. return $this->bundleImpl->getErrorMessage();
  63. }
  64. }