Configuration.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * This file is part of Alchemy\BinaryDriver.
  4. *
  5. * (c) Alchemy <info@alchemy.fr>
  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 Alchemy\BinaryDriver;
  11. class Configuration implements ConfigurationInterface
  12. {
  13. private $data;
  14. public function __construct(array $data = array())
  15. {
  16. $this->data = $data;
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function getIterator()
  22. {
  23. return new \ArrayIterator($this->data);
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function get($key, $default = null)
  29. {
  30. return isset($this->data[$key]) ? $this->data[$key] : $default;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function set($key, $value)
  36. {
  37. $this->data[$key] = $value;
  38. return $this;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function has($key)
  44. {
  45. return array_key_exists($key, $this->data);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function remove($key)
  51. {
  52. $value = $this->get($key);
  53. unset($this->data[$key]);
  54. return $value;
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function all()
  60. {
  61. return $this->data;
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function offsetExists($offset)
  67. {
  68. return $this->has($offset);
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function offsetGet($offset)
  74. {
  75. return $this->get($offset);
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function offsetSet($offset, $value)
  81. {
  82. $this->set($offset, $value);
  83. }
  84. /**
  85. * {@inheritdoc}
  86. */
  87. public function offsetUnset($offset)
  88. {
  89. $this->remove($offset);
  90. }
  91. }