StorageWrapper.php

  1. 8.0.x lib/Drush/Config/StorageWrapper.php
  2. master lib/Drush/Config/StorageWrapper.php

Definition of Drush\Config\StorageWrapper.

Namespace

Drush\Config

Classes

Namesort descending Description
StorageWrapper

File

lib/Drush/Config/StorageWrapper.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of Drush\Config\StorageWrapper.
  5. */
  6. namespace Drush\Config;
  7. use Drupal\Core\Config\StorageInterface;
  8. class StorageWrapper implements StorageInterface {
  9. /**
  10. * The storage container that we are wrapping.
  11. *
  12. * @var \Drupal\Core\Config\StorageInterface
  13. */
  14. protected $storage;
  15. protected $filters;
  16. /**
  17. * Create a StorageWrapper with some storage and a filter.
  18. */
  19. function __construct($storage, $filterOrFilters) {
  20. $this->storage = $storage;
  21. $this->filters = is_array($filterOrFilters) ? $filterOrFilters : array($filterOrFilters);
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function exists($name) {
  27. return $this->storage->exists($name);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function read($name) {
  33. $data = $this->storage->read($name);
  34. foreach ($this->filters as $filter) {
  35. $data = $filter->filterRead($name, $data);
  36. }
  37. return $data;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function readMultiple(array $names) {
  43. $dataList = $this->storage->readMultiple($names);
  44. $result = array();
  45. foreach ($dataList as $name => $data) {
  46. foreach ($this->filters as $filter) {
  47. $data = $filter->filterRead($name, $data);
  48. }
  49. $result[$name] = $data;
  50. }
  51. return $result;
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function write($name, array $data) {
  57. foreach ($this->filters as $filter) {
  58. $data = $filter->filterWrite($name, $data, $this->storage);
  59. }
  60. return $this->storage->write($name, $data);
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function delete($name) {
  66. return $this->storage->delete($name);
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function rename($name, $new_name) {
  72. return $this->storage->rename($name, $new_name);
  73. }
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function encode($data) {
  78. return $this->storage->encode($data);
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function decode($raw) {
  84. return $this->storage->decode($raw);
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function listAll($prefix = '') {
  90. return $this->storage->listAll($prefix);
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function deleteAll($prefix = '') {
  96. return $this->storage->deleteAll($prefix);
  97. }
  98. /**
  99. * {@inheritdoc}
  100. */
  101. public function createCollection($collection) {
  102. return $this->storage->createCollection($collection);
  103. }
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public function getAllCollectionNames() {
  108. return $this->storage->getAllCollectionNames();
  109. }
  110. /**
  111. * {@inheritdoc}
  112. */
  113. public function getCollectionName() {
  114. return $this->storage->getCollectionName();
  115. }
  116. }