1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PEIP\Data; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the PEIP package. |
7
|
|
|
* (c) 2009-2016 Timo Michna <timomichna/yahoo.de> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* StoreCollection |
15
|
|
|
* Class to act as a namespaced store for arbitrary values. |
16
|
|
|
* |
17
|
|
|
* @author Timo Michna <timomichna/yahoo.de> |
18
|
|
|
* @extends \PEIP\Data\InternalStoreAbstract |
19
|
|
|
* @implements \PEIP\INF\Data\StoreCollection |
20
|
|
|
*/ |
21
|
|
|
class StoreCollection extends \PEIP\Data\InternalStoreAbstract implements \PEIP\INF\Data\StoreCollection |
22
|
|
|
{ |
23
|
|
|
protected $factory, |
24
|
|
|
$stores; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* constructor. |
28
|
|
|
* |
29
|
|
|
* @param \PEIP\INF\Factory\DedicatedFactory $factory a factory instance to create new stores |
30
|
|
|
* |
31
|
|
|
* @return |
32
|
|
|
*/ |
33
|
|
|
public function __construct(\PEIP\INF\Factory\DedicatedFactory $factory) |
34
|
|
|
{ |
35
|
|
|
$this->factory = $factory; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns a \PEIP\INF\Data\Store instance for a given namespace. |
40
|
|
|
* Creates a new \PEIP\INF\Data\Store instance if none is allerady set for given namespace. |
41
|
|
|
* |
42
|
|
|
* @param string $namespace the namespace to get the store for |
43
|
|
|
* |
44
|
|
|
* @return \PEIP\INF\Data\Store a store for given namespace |
45
|
|
|
*/ |
46
|
|
|
protected function getStoreOrCreate($namespace) |
47
|
|
|
{ |
48
|
|
|
if (!$this->hasPrivateValue($namespace)) { |
|
|
|
|
49
|
|
|
$store = $this->factory->build(); |
50
|
|
|
if ($store instanceof \PEIP\INF\Data\Store) { |
51
|
|
|
$this->setPrivateValue($namespace, $store); |
|
|
|
|
52
|
|
|
} else { |
53
|
|
|
throw new \Exception('Could not build Instance of \PEIP\INF\Data\Store from factory.'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->getPrivateValue($namespace); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Sets all values for a namespace as key/value pairs array. |
62
|
|
|
* |
63
|
|
|
* @param string $namespace the namspace to set values for |
64
|
|
|
* @param array $values key/value pairs to store |
65
|
|
|
* |
66
|
|
|
* @return |
67
|
|
|
*/ |
68
|
|
|
public function setValues($namespace, array $values) |
69
|
|
|
{ |
70
|
|
|
$this->getStoreOrCreate($namespace)->setValues($values); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Adds values for a namespace as key/value pairs array. |
75
|
|
|
* Overwrites value for a key if allready has been set. |
76
|
|
|
* |
77
|
|
|
* @param string $namespace the namspace to add values to |
78
|
|
|
* @param $values |
79
|
|
|
* |
80
|
|
|
* @return |
81
|
|
|
*/ |
82
|
|
|
public function addValues($namespace, array $values) |
83
|
|
|
{ |
84
|
|
|
$this->getStoreOrCreate($namespace)->addValues($values); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* returns all values for a namespace as key/value pairs. |
89
|
|
|
* |
90
|
|
|
* @param string $namespace the namspace to return values for |
91
|
|
|
* |
92
|
|
|
* @return array stored key/value pairs |
93
|
|
|
*/ |
94
|
|
|
public function getValues($namespace) |
95
|
|
|
{ |
96
|
|
|
$this->getStoreOrCreate($namespace)->getValues(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Returns the value for a given key on a given namespace. |
101
|
|
|
* |
102
|
|
|
* @param string $namespace the namspace to return value for |
103
|
|
|
* @param string $key the key to return value for |
104
|
|
|
* |
105
|
|
|
* @return mixed value for the given key on the given namespace |
106
|
|
|
*/ |
107
|
|
|
public function getValue($namespace, $key) |
108
|
|
|
{ |
109
|
|
|
$this->getStoreOrCreate($namespace)->getValue($key); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Stores the value for a given key on a given namespace. |
114
|
|
|
* |
115
|
|
|
* @param string $namespace the namspace to store a value for |
116
|
|
|
* @param string $key key to store value for |
117
|
|
|
* @param mixed $value the value to store |
118
|
|
|
* |
119
|
|
|
* @return |
120
|
|
|
*/ |
121
|
|
|
public function setValue($namespace, $key, $value) |
122
|
|
|
{ |
123
|
|
|
$this->getStoreOrCreate($namespace)->setValues($values); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Checks wether a value is stored for given key on a given namespace. |
128
|
|
|
* |
129
|
|
|
* @param $namespace the namespace to look for a value |
130
|
|
|
* @param string $key the key to look for a value |
131
|
|
|
* |
132
|
|
|
* @return |
133
|
|
|
*/ |
134
|
|
|
public function hasValue($namespace, $key) |
135
|
|
|
{ |
136
|
|
|
$this->getStoreOrCreate($namespace)->hasValue($key); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Removes the value for a given key on a given namespace. |
141
|
|
|
* |
142
|
|
|
* @param string $namespace the namespace to remove the value from |
143
|
|
|
* @param string $key the key to remove the value from |
144
|
|
|
* |
145
|
|
|
* @return |
146
|
|
|
*/ |
147
|
|
|
public function deleteValue($namespace, $key) |
148
|
|
|
{ |
149
|
|
|
$this->getStoreOrCreate($namespace)->setValues($values); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Sets a store instance (\PEIP\INF\Data\Store) for a given namespace. |
154
|
|
|
* |
155
|
|
|
* @param string $namespace the namespace to set the store for |
156
|
|
|
* @param \PEIP\INF\Data\Store $store the store instance to register for the namespace |
157
|
|
|
* |
158
|
|
|
* @return |
159
|
|
|
*/ |
160
|
|
|
public function setStore($namespace, \PEIP\INF\Data\Store $store) |
161
|
|
|
{ |
162
|
|
|
$this->setInternalValue($namespace, $store); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* returns the store instance for a given namespace. |
167
|
|
|
* |
168
|
|
|
* @param string $namespace the namespace to return the store for |
169
|
|
|
* |
170
|
|
|
* @return \PEIP\INF\Data\Store store instance for given namespace (if set) |
171
|
|
|
*/ |
172
|
|
|
public function getStore($namespace) |
173
|
|
|
{ |
174
|
|
|
$this->getInternalValue($namespace); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Checks wether a store has been registered for a given namespace. |
179
|
|
|
* |
180
|
|
|
* @param string $namespace the namespace to check for a store instance |
181
|
|
|
* |
182
|
|
|
* @return bool wether a store has been registered for the given namespace |
183
|
|
|
*/ |
184
|
|
|
public function hasStore($namespace) |
185
|
|
|
{ |
186
|
|
|
return $this->hasInternalValue($namespace); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Unregisters the store for a given namespace. |
191
|
|
|
* |
192
|
|
|
* @param string $namespace the namespace to ungegister the store for |
193
|
|
|
* |
194
|
|
|
* @return |
195
|
|
|
*/ |
196
|
|
|
public function deleteStore($namespace) |
197
|
|
|
{ |
198
|
|
|
return $this->deleteInternalValue($namespace); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.