ReadOnlyStorage.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace Drupal\Core\Config;
  3. /**
  4. * A ReadOnlyStorage decorates a storage and does not allow writing to it.
  5. */
  6. class ReadOnlyStorage implements StorageInterface {
  7. /**
  8. * The config storage that we are decorating.
  9. *
  10. * @var \Drupal\Core\Config\StorageInterface
  11. */
  12. protected $storage;
  13. /**
  14. * Create a ReadOnlyStorage decorating another storage.
  15. *
  16. * @param \Drupal\Core\Config\StorageInterface $storage
  17. * The decorated storage.
  18. */
  19. public function __construct(StorageInterface $storage) {
  20. $this->storage = $storage;
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function exists($name) {
  26. return $this->storage->exists($name);
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function read($name) {
  32. return $this->storage->read($name);
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function readMultiple(array $names) {
  38. return $this->storage->readMultiple($names);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function write($name, array $data) {
  44. throw new \BadMethodCallException(__METHOD__ . ' is not allowed on a ReadOnlyStorage');
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function delete($name) {
  50. throw new \BadMethodCallException(__METHOD__ . ' is not allowed on a ReadOnlyStorage');
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function rename($name, $new_name) {
  56. throw new \BadMethodCallException(__METHOD__ . ' is not allowed on a ReadOnlyStorage');
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function encode($data) {
  62. return $this->storage->encode($data);
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function decode($raw) {
  68. return $this->storage->decode($raw);
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function listAll($prefix = '') {
  74. return $this->storage->listAll($prefix);
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function deleteAll($prefix = '') {
  80. throw new \BadMethodCallException(__METHOD__ . ' is not allowed on a ReadOnlyStorage');
  81. }
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function createCollection($collection) {
  86. return new static($this->storage->createCollection($collection));
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function getAllCollectionNames() {
  92. return $this->storage->getAllCollectionNames();
  93. }
  94. /**
  95. * {@inheritdoc}
  96. */
  97. public function getCollectionName() {
  98. return $this->storage->getCollectionName();
  99. }
  100. }