1 | <?php |
||
27 | abstract class AbstractEndpoint extends AbstractResource implements EndpointInterface |
||
28 | { |
||
29 | /** |
||
30 | * Kind. |
||
31 | */ |
||
32 | public const KIND = 'Endpoint'; |
||
33 | |||
34 | /** |
||
35 | * Endpoint name. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $name; |
||
40 | |||
41 | /** |
||
42 | * CollectionInterface. |
||
43 | * |
||
44 | * @var CollectionInterface |
||
45 | */ |
||
46 | protected $collection; |
||
47 | |||
48 | /** |
||
49 | * Logger. |
||
50 | * |
||
51 | * @var LoggerInterface |
||
52 | */ |
||
53 | protected $logger; |
||
54 | |||
55 | /** |
||
56 | * Filter All. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $filter_all; |
||
61 | |||
62 | /** |
||
63 | * Filter One. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $filter_one; |
||
68 | |||
69 | /** |
||
70 | * Import. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $import = []; |
||
75 | |||
76 | /** |
||
77 | * Type. |
||
78 | * |
||
79 | * @var string |
||
80 | */ |
||
81 | protected $type; |
||
82 | |||
83 | /** |
||
84 | * Flush. |
||
85 | * |
||
86 | * @var bool |
||
87 | */ |
||
88 | protected $flush = false; |
||
89 | |||
90 | /** |
||
91 | * Workflow factory. |
||
92 | * |
||
93 | * @var WorkflowFactory |
||
94 | */ |
||
95 | protected $workflow_factory; |
||
96 | |||
97 | /** |
||
98 | * Endpoint object identifiers. |
||
99 | * |
||
100 | * @var string |
||
101 | */ |
||
102 | protected $identifier; |
||
103 | |||
104 | /** |
||
105 | * Init endpoint. |
||
106 | */ |
||
107 | 99 | public function __construct(string $name, string $type, CollectionInterface $collection, WorkflowFactory $workflow_factory, LoggerInterface $logger, array $resource = []) |
|
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function setup(bool $simulate = false): EndpointInterface |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function getKind(): string |
||
136 | |||
137 | /** |
||
138 | * Set options. |
||
139 | */ |
||
140 | 25 | public function setOptions(array $config = []): EndpointInterface |
|
141 | { |
||
142 | 25 | foreach ($config as $option => $value) { |
|
143 | switch ($option) { |
||
144 | 25 | case 'flush': |
|
145 | 25 | case 'import': |
|
146 | 25 | case 'identifier': |
|
147 | 25 | case 'filter_one': |
|
148 | 5 | case 'filter_all': |
|
149 | 25 | $this->{$option} = $value; |
|
150 | |||
151 | 25 | break; |
|
152 | default: |
||
153 | throw new InvalidArgumentException('unknown option '.$option.' given'); |
||
154 | } |
||
155 | } |
||
156 | |||
157 | 25 | return $this; |
|
158 | } |
||
159 | |||
160 | /** |
||
161 | * {@inheritdoc} |
||
162 | */ |
||
163 | public function decorate(ServerRequestInterface $request): array |
||
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | 1 | public function shutdown(bool $simulate = false): EndpointInterface |
|
205 | |||
206 | /** |
||
207 | * {@inheritdoc} |
||
208 | */ |
||
209 | public function flushRequired(): bool |
||
213 | |||
214 | /** |
||
215 | * {@inheritdoc} |
||
216 | */ |
||
217 | public function flush(bool $simulate = false): bool |
||
221 | |||
222 | /** |
||
223 | * {@inheritdoc} |
||
224 | */ |
||
225 | public function getCollection(): CollectionInterface |
||
229 | |||
230 | /** |
||
231 | * {@inheritdoc} |
||
232 | */ |
||
233 | public function getResourceIdentifier(): ?string |
||
237 | |||
238 | /** |
||
239 | * {@inheritdoc} |
||
240 | */ |
||
241 | public function getImport(): array |
||
245 | |||
246 | /** |
||
247 | * {@inheritdoc} |
||
248 | */ |
||
249 | 3 | public function exists(array $object): bool |
|
261 | |||
262 | /** |
||
263 | * {@inheritdoc} |
||
264 | */ |
||
265 | public function hasWorkflow(string $name): bool |
||
269 | |||
270 | /** |
||
271 | * {@inheritdoc} |
||
272 | */ |
||
273 | public function getWorkflow(string $name): WorkflowInterface |
||
277 | |||
278 | /** |
||
279 | * {@inheritdoc} |
||
280 | */ |
||
281 | public function getWorkflows(array $workflows = [], ?int $offset = null, ?int $limit = null): Generator |
||
287 | |||
288 | /** |
||
289 | * {@inheritdoc} |
||
290 | */ |
||
291 | public function count(?array $query = null): int |
||
295 | |||
296 | /** |
||
297 | * {@inheritdoc} |
||
298 | */ |
||
299 | public function getType(): string |
||
303 | |||
304 | /** |
||
305 | * {@inheritdoc} |
||
306 | */ |
||
307 | 35 | public function getIdentifier(): string |
|
311 | |||
312 | /** |
||
313 | * {@inheritdoc} |
||
314 | */ |
||
315 | 18 | public function getFilterOne(array $object): ?array |
|
323 | |||
324 | /** |
||
325 | * {@inheritdoc} |
||
326 | */ |
||
327 | 4 | public function getFilterAll(): ?array |
|
335 | |||
336 | /** |
||
337 | * Build endpoint object. |
||
338 | */ |
||
339 | 6 | protected function build(array $object, $filter = null): EndpointObjectInterface |
|
346 | |||
347 | /** |
||
348 | * Parse and replace string with attribute values. |
||
349 | */ |
||
350 | private function parseAttribute(string $string, array $data): string |
||
366 | } |
||
367 |