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