1 | <?php |
||
2 | |||
3 | namespace kalanis\Restful\Converters; |
||
4 | |||
5 | |||
6 | /** |
||
7 | * ResourceConverter |
||
8 | * @package kalanis\Restful\Converters |
||
9 | */ |
||
10 | class ResourceConverter |
||
11 | { |
||
12 | |||
13 | /** @var array<IConverter<string|int, mixed>> */ |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
14 | private array $converters = []; |
||
15 | |||
16 | /** |
||
17 | * Get converters |
||
18 | * @return array<IConverter<string|int, mixed>> |
||
0 ignored issues
–
show
|
|||
19 | */ |
||
20 | public function getConverters(): array |
||
21 | { |
||
22 | return $this->converters; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Add resource data converter to list |
||
27 | * @param IConverter<string|int, mixed> $converter |
||
28 | * @return $this |
||
29 | */ |
||
30 | public function addConverter(IConverter $converter): self |
||
31 | { |
||
32 | 1 | $this->converters[] = $converter; |
|
33 | 1 | return $this; |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * Converts data from resource using converters |
||
38 | * @param array<string|int, mixed> $data |
||
39 | * @return array<string|int, mixed> |
||
40 | */ |
||
41 | public function convert(array $data): array |
||
42 | { |
||
43 | 1 | foreach ($this->converters as $converter) { |
|
44 | 1 | $data = $converter->convert($data); |
|
45 | } |
||
46 | |||
47 | 1 | return $data; |
|
48 | } |
||
49 | } |
||
50 |