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 | 34 | 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 | 35 | public function setDefaultDataset(array $dataset) : object |
|
50 | |||
51 | |||
52 | |||
53 | /** |
||
54 | * Get the default dataset that is used. |
||
55 | * |
||
56 | * @return self |
||
57 | */ |
||
58 | 10 | public function getDefaultDataset() : array |
|
62 | |||
63 | |||
64 | |||
65 | /** |
||
66 | * Fill the session with default data that are read from files. |
||
67 | * |
||
68 | * @throws Anax\RemServer\Exception when bad configuration. |
||
69 | * |
||
70 | * @return self |
||
71 | */ |
||
72 | 25 | public function init() |
|
87 | |||
88 | |||
89 | |||
90 | /** |
||
91 | * Check if there is a dataset stored. |
||
92 | * |
||
93 | * @return boolean true if dataset exists in session, else false |
||
94 | */ |
||
95 | 24 | public function hasDataset() |
|
99 | |||
100 | |||
101 | |||
102 | /** |
||
103 | * Get (or create) a subset of data. |
||
104 | * |
||
105 | * @param string $key for data subset. |
||
106 | * |
||
107 | * @return array with the dataset |
||
108 | */ |
||
109 | 20 | public function getDataset($key) |
|
117 | |||
118 | |||
119 | |||
120 | /** |
||
121 | * Save (the modified) dataset. |
||
122 | * |
||
123 | * @param string $key for data subset. |
||
124 | * @param array $dataset the data to save. |
||
125 | * |
||
126 | * @return self |
||
127 | */ |
||
128 | 11 | public function saveDataset($key, $dataset) |
|
135 | |||
136 | |||
137 | |||
138 | /** |
||
139 | * Get an item from a dataset. |
||
140 | * |
||
141 | * @param string $key for the dataset |
||
142 | * @param string $itemId for the item to get |
||
143 | * |
||
144 | * @return array|null array with item if found, else null |
||
145 | */ |
||
146 | 11 | public function getItem($key, $itemId) |
|
157 | |||
158 | |||
159 | |||
160 | /** |
||
161 | * Add an item to a dataset. |
||
162 | * |
||
163 | * @param string $key for the dataset |
||
164 | * @param array $item to add |
||
165 | * |
||
166 | * @return array as new item inserted |
||
167 | */ |
||
168 | 3 | public function addItem($key, $item) |
|
184 | |||
185 | |||
186 | |||
187 | /** |
||
188 | * Upsert/replace an item to a dataset. |
||
189 | * |
||
190 | * @param string $keyDataset for the dataset |
||
191 | * @param string $itemId where to store it |
||
192 | * @param string $entry to add |
||
193 | * |
||
194 | * @return array as item upserted |
||
195 | */ |
||
196 | 4 | public function upsertItem($keyDataset, $itemId, $entry) |
|
218 | |||
219 | |||
220 | |||
221 | /** |
||
222 | * Delete an item from the dataset. |
||
223 | * |
||
224 | * @param string $keyDataset for the dataset |
||
225 | * @param string $itemId to delete |
||
226 | * |
||
227 | * @return void |
||
228 | */ |
||
229 | 4 | public function deleteItem($keyDataset, $itemId) |
|
242 | } |
||
243 |