1 | <?php |
||
12 | class RemServer implements ConfigureInterface |
||
13 | { |
||
14 | use ConfigureTrait; |
||
15 | |||
16 | |||
17 | |||
18 | /** |
||
19 | * @var object $session inject a reference to the session. |
||
20 | */ |
||
21 | protected $session; |
||
22 | |||
23 | |||
24 | |||
25 | /** |
||
26 | * @var string $key to use when storing in session. |
||
27 | */ |
||
28 | const KEY = "remserver"; |
||
29 | |||
30 | |||
31 | |||
32 | /** |
||
33 | * Inject dependency to $session. |
||
34 | * |
||
35 | * @param SessionInterface $session object representing session. |
||
36 | * |
||
37 | * @return self |
||
38 | */ |
||
39 | public function injectSession(SessionInterface $session) |
||
44 | |||
45 | |||
46 | |||
47 | /** |
||
48 | * Fill the session with default data that are read from files. |
||
49 | * |
||
50 | * @throws Exception when bad configuration. |
||
51 | * |
||
52 | * @return self |
||
53 | */ |
||
54 | public function init() |
||
71 | |||
72 | |||
73 | |||
74 | /** |
||
75 | * Check if there is a dataset stored. |
||
76 | * |
||
77 | * @return boolean true if dataset exists in session, else false |
||
78 | */ |
||
79 | public function hasDataset() |
||
83 | |||
84 | |||
85 | |||
86 | /** |
||
87 | * Get (or create) a subset of data. |
||
88 | * |
||
89 | * @param string $key for data subset. |
||
90 | * |
||
91 | * @return array with the dataset |
||
92 | */ |
||
93 | public function getDataset($key) |
||
101 | |||
102 | |||
103 | |||
104 | /** |
||
105 | * Save (the modified) dataset. |
||
106 | * |
||
107 | * @param string $key for data subset. |
||
108 | * @param array $dataset the data to save. |
||
109 | * |
||
110 | * @return self |
||
111 | */ |
||
112 | public function saveDataset($key, $dataset) |
||
119 | |||
120 | |||
121 | |||
122 | /** |
||
123 | * Get an item from a dataset. |
||
124 | * |
||
125 | * @param string $key for the dataset |
||
126 | * @param string $itemId for the item to get |
||
127 | * |
||
128 | * @return array|null array with item if found, else null |
||
129 | */ |
||
130 | public function getItem($key, $itemId) |
||
141 | |||
142 | |||
143 | |||
144 | /** |
||
145 | * Add an item to a dataset. |
||
146 | * |
||
147 | * @param string $key for the dataset |
||
148 | * @param string $item to add |
||
149 | * |
||
150 | * @return array as new item inserted |
||
151 | */ |
||
152 | public function addItem($key, $item) |
||
168 | |||
169 | |||
170 | |||
171 | /** |
||
172 | * Upsert/replace an item to a dataset. |
||
173 | * |
||
174 | * @param string $keyDataset for the dataset |
||
175 | * @param string $itemId where to store it |
||
176 | * @param string $entry to add |
||
177 | * |
||
178 | * @return array as item upserted |
||
179 | */ |
||
180 | public function upsertItem($keyDataset, $itemId, $entry) |
||
202 | |||
203 | |||
204 | |||
205 | /** |
||
206 | * Delete an item from the dataset. |
||
207 | * |
||
208 | * @param string $keyDataset for the dataset |
||
209 | * @param string $itemId to delete |
||
210 | * |
||
211 | * @return void |
||
212 | */ |
||
213 | public function deleteItem($keyDataset, $itemId) |
||
226 | } |
||
227 |