f42e66f358894c9d3d4531acad741b0bd14cb029
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / State / StateWrapper.php
1 <?php
2
3 namespace Drupal\webprofiler\State;
4
5 use Drupal\Core\State\StateInterface;
6 use Drupal\webprofiler\DataCollector\StateDataCollector;
7
8 /**
9  * Class StateWrapper.
10  */
11 class StateWrapper implements StateInterface {
12
13   /**
14    * The system state.
15    *
16    * @var \Drupal\Core\State\StateInterface
17    */
18   private $state;
19
20   /**
21    * The state data collector.
22    *
23    * @var \Drupal\webprofiler\DataCollector\StateDataCollector
24    */
25   private $dataCollector;
26
27   /**
28    * StateWrapper constructor.
29    *
30    * @param \Drupal\Core\State\StateInterface $state
31    *   The system state.
32    * @param \Drupal\webprofiler\DataCollector\StateDataCollector $dataCollector
33    *   The state data collector.
34    */
35   public function __construct(StateInterface $state, StateDataCollector $dataCollector) {
36     $this->state = $state;
37     $this->dataCollector = $dataCollector;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function get($key, $default = NULL) {
44     $this->dataCollector->addState($key);
45
46     return $this->state->get($key, $default);
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getMultiple(array $keys) {
53     foreach ($keys as $key) {
54       $this->dataCollector->addState($key);
55     }
56
57     return $this->state->getMultiple($keys);
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function set($key, $value) {
64     $this->state->set($key, $value);
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   public function setMultiple(array $data) {
71     $this->state->setMultiple($data);
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   public function delete($key) {
78     $this->state->delete($key);
79   }
80
81   /**
82    * {@inheritdoc}
83    */
84   public function deleteMultiple(array $keys) {
85     $this->state->deleteMultiple($keys);
86   }
87
88   /**
89    * {@inheritdoc}
90    */
91   public function resetCache() {
92     $this->state->resetCache();
93   }
94
95   /**
96    * Passes through all non-tracked calls onto the decorated object.
97    *
98    * @param string $method
99    *   The called method.
100    * @param mixed $args
101    *   The passed in arguments.
102    *
103    * @return mixed
104    *   The return argument of the call.
105    */
106   public function __call($method, $args) {
107     return call_user_func_array([$this->state, $method], $args);
108   }
109
110 }