1 | <?php |
||
10 | class RemServer |
||
11 | { |
||
12 | /** |
||
13 | * @var array $dataset the dataset to add as default dataset. |
||
14 | * @var object $session inject a reference to the session. |
||
15 | * @var string $key to use when storing in session. |
||
16 | */ |
||
17 | private $dataset = []; |
||
18 | protected $session; |
||
19 | const KEY = "remserver"; |
||
20 | |||
21 | |||
22 | |||
23 | /** |
||
24 | * Inject dependency to $session. |
||
25 | * |
||
26 | * @param SessionInterface $session object representing session. |
||
27 | * |
||
28 | * @return self |
||
29 | */ |
||
30 | 1 | public function injectSession(SessionInterface $session) : object |
|
35 | |||
36 | |||
37 | |||
38 | /** |
||
39 | * Set the default dataset to use. |
||
40 | * |
||
41 | * @param array $dataset array with absolute paths to json files to load. |
||
42 | * |
||
43 | * @return self |
||
44 | */ |
||
45 | public function setDefaultDataset(array $dataset) : object |
||
50 | |||
51 | |||
52 | |||
53 | /** |
||
54 | * Get the default dataset that is used. |
||
55 | * |
||
56 | * @return self |
||
57 | */ |
||
58 | public function getDefaultDataset() : array |
||
62 | |||
63 | |||
64 | |||
65 | /** |
||
66 | * Fill the session with default data that are read from files. |
||
67 | * |
||
68 | * @throws Exception when bad configuration. |
||
69 | * |
||
70 | * @return self |
||
71 | */ |
||
72 | public function init() |
||
84 | |||
85 | |||
86 | |||
87 | /** |
||
88 | * Check if there is a dataset stored. |
||
89 | * |
||
90 | * @return boolean true if dataset exists in session, else false |
||
91 | */ |
||
92 | public function hasDataset() |
||
96 | |||
97 | |||
98 | |||
99 | /** |
||
100 | * Get (or create) a subset of data. |
||
101 | * |
||
102 | * @param string $key for data subset. |
||
103 | * |
||
104 | * @return array with the dataset |
||
105 | */ |
||
106 | public function getDataset($key) |
||
114 | |||
115 | |||
116 | |||
117 | /** |
||
118 | * Save (the modified) dataset. |
||
119 | * |
||
120 | * @param string $key for data subset. |
||
121 | * @param array $dataset the data to save. |
||
122 | * |
||
123 | * @return self |
||
124 | */ |
||
125 | public function saveDataset($key, $dataset) |
||
132 | |||
133 | |||
134 | |||
135 | /** |
||
136 | * Get an item from a dataset. |
||
137 | * |
||
138 | * @param string $key for the dataset |
||
139 | * @param string $itemId for the item to get |
||
140 | * |
||
141 | * @return array|null array with item if found, else null |
||
142 | */ |
||
143 | public function getItem($key, $itemId) |
||
154 | |||
155 | |||
156 | |||
157 | /** |
||
158 | * Add an item to a dataset. |
||
159 | * |
||
160 | * @param string $key for the dataset |
||
161 | * @param array $item to add |
||
162 | * |
||
163 | * @return array as new item inserted |
||
164 | */ |
||
165 | public function addItem($key, $item) |
||
181 | |||
182 | |||
183 | |||
184 | /** |
||
185 | * Upsert/replace an item to a dataset. |
||
186 | * |
||
187 | * @param string $keyDataset for the dataset |
||
188 | * @param string $itemId where to store it |
||
189 | * @param string $entry to add |
||
190 | * |
||
191 | * @return array as item upserted |
||
192 | */ |
||
193 | public function upsertItem($keyDataset, $itemId, $entry) |
||
215 | |||
216 | |||
217 | |||
218 | /** |
||
219 | * Delete an item from the dataset. |
||
220 | * |
||
221 | * @param string $keyDataset for the dataset |
||
222 | * @param string $itemId to delete |
||
223 | * |
||
224 | * @return void |
||
225 | */ |
||
226 | public function deleteItem($keyDataset, $itemId) |
||
239 | } |
||
240 |