ArrayAccessibleResourceBundle.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Data\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/64356.
  16. * This class can be removed once that bug is fixed.
  17. *
  18. * @author Bernhard Schussek <bschussek@gmail.com>
  19. *
  20. * @internal
  21. */
  22. class ArrayAccessibleResourceBundle implements \ArrayAccess, \IteratorAggregate, \Countable
  23. {
  24. private $bundleImpl;
  25. public function __construct(\ResourceBundle $bundleImpl)
  26. {
  27. $this->bundleImpl = $bundleImpl;
  28. }
  29. public function get($offset)
  30. {
  31. $value = $this->bundleImpl->get($offset);
  32. return $value instanceof \ResourceBundle ? new static($value) : $value;
  33. }
  34. public function offsetExists($offset): bool
  35. {
  36. return null !== $this->bundleImpl->get($offset);
  37. }
  38. public function offsetGet($offset)
  39. {
  40. return $this->get($offset);
  41. }
  42. public function offsetSet($offset, $value)
  43. {
  44. throw new BadMethodCallException('Resource bundles cannot be modified.');
  45. }
  46. public function offsetUnset($offset)
  47. {
  48. throw new BadMethodCallException('Resource bundles cannot be modified.');
  49. }
  50. public function getIterator(): \Traversable
  51. {
  52. return $this->bundleImpl;
  53. }
  54. public function count(): int
  55. {
  56. return $this->bundleImpl->count();
  57. }
  58. public function getErrorCode()
  59. {
  60. return $this->bundleImpl->getErrorCode();
  61. }
  62. public function getErrorMessage()
  63. {
  64. return $this->bundleImpl->getErrorMessage();
  65. }
  66. }