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 | 58 | 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 | 9 | public function setOptions(?array $config = null): EndpointInterface |
|
141 | { |
||
142 | 9 | if ($config === null) { |
|
143 | return $this; |
||
144 | } |
||
145 | |||
146 | 9 | foreach ($config as $option => $value) { |
|
147 | 9 | switch ($option) { |
|
148 | 9 | case 'flush': |
|
149 | 9 | case 'import': |
|
150 | 9 | case 'identifier': |
|
151 | 9 | case 'filter_one': |
|
152 | 2 | case 'filter_all': |
|
153 | 9 | $this->{$option} = $value; |
|
154 | |||
155 | 9 | break; |
|
156 | default: |
||
157 | 9 | throw new InvalidArgumentException('unknown option '.$option.' given'); |
|
158 | } |
||
159 | } |
||
160 | |||
161 | 9 | return $this; |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | public function decorate(ServerRequestInterface $request): array |
||
201 | |||
202 | /** |
||
203 | * {@inheritdoc} |
||
204 | */ |
||
205 | public function shutdown(bool $simulate = false): EndpointInterface |
||
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | public function flushRequired(): bool |
||
217 | |||
218 | /** |
||
219 | * {@inheritdoc} |
||
220 | */ |
||
221 | public function flush(bool $simulate = false): bool |
||
225 | |||
226 | /** |
||
227 | * {@inheritdoc} |
||
228 | */ |
||
229 | public function getCollection(): CollectionInterface |
||
233 | |||
234 | /** |
||
235 | * {@inheritdoc} |
||
236 | */ |
||
237 | public function getResourceIdentifier(): array |
||
238 | { |
||
239 | return $this->identifier; |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * {@inheritdoc} |
||
244 | */ |
||
245 | public function getImport(): array |
||
249 | |||
250 | /** |
||
251 | * {@inheritdoc} |
||
252 | */ |
||
253 | 3 | public function exists(array $object): bool |
|
265 | |||
266 | /** |
||
267 | * {@inheritdoc} |
||
268 | */ |
||
269 | public function hasWorkflow(string $name): bool |
||
273 | |||
274 | /** |
||
275 | * {@inheritdoc} |
||
276 | */ |
||
277 | public function getWorkflow(string $name): WorkflowInterface |
||
281 | |||
282 | /** |
||
283 | * {@inheritdoc} |
||
284 | */ |
||
285 | public function getWorkflows(array $workflows = [], ?int $offset = null, ?int $limit = null): Generator |
||
291 | |||
292 | /** |
||
293 | * {@inheritdoc} |
||
294 | */ |
||
295 | public function getType(): string |
||
299 | |||
300 | /** |
||
301 | * {@inheritdoc} |
||
302 | */ |
||
303 | 22 | public function getIdentifier(): string |
|
307 | |||
308 | /** |
||
309 | * {@inheritdoc} |
||
310 | */ |
||
311 | 7 | public function getFilterOne(array $object) |
|
315 | |||
316 | /** |
||
317 | * {@inheritdoc} |
||
318 | */ |
||
319 | 2 | public function getFilterAll() |
|
323 | |||
324 | /** |
||
325 | * Build endpoint object. |
||
326 | */ |
||
327 | 2 | protected function build(array $object): EndpointObjectInterface |
|
331 | |||
332 | /** |
||
333 | * Parse and replace string with attribute values. |
||
334 | */ |
||
335 | private function parseAttribute(string $string, array $data): string |
||
351 | } |
||
352 |