1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Micro framework package. |
||
7 | * |
||
8 | * (c) Stanislau Komar <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Micro\Library\DTO\Preparation; |
||
15 | |||
16 | use Micro\Library\DTO\ClassDef\ClassDefinition; |
||
17 | use Micro\Library\DTO\Reader\ReaderInterface; |
||
18 | |||
19 | class CollectionPreparation implements CollectionPreparationInterface |
||
20 | { |
||
21 | /** |
||
22 | * @param iterable<PreparationProcessorInterface> $preparationProcessor |
||
23 | */ |
||
24 | 6 | public function __construct(private iterable $preparationProcessor) |
|
25 | { |
||
26 | 6 | } |
|
27 | |||
28 | /** |
||
29 | * {@inheritDoc} |
||
30 | */ |
||
31 | 6 | public function process(ReaderInterface $reader): iterable |
|
32 | { |
||
33 | 6 | $classCollection = $reader->read(); |
|
34 | 4 | if ($classCollection instanceof \Traversable) { |
|
35 | 4 | $classCollection = iterator_to_array($classCollection); |
|
36 | } |
||
37 | |||
38 | 3 | $classList = $this->createClassList($classCollection); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
39 | |||
40 | 3 | foreach ($classCollection as $classDef) { |
|
41 | 3 | $classDefObj = new ClassDefinition(); |
|
42 | 3 | foreach ($this->preparationProcessor as $processor) { |
|
43 | 3 | $processor->process($classDef, $classDefObj, $classList); |
|
44 | } |
||
45 | |||
46 | 1 | yield $classDefObj; |
|
47 | } |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param array<string, mixed> $classes |
||
52 | * |
||
53 | * @return array<class-string> |
||
0 ignored issues
–
show
|
|||
54 | */ |
||
55 | 3 | protected function createClassList(array $classes): array |
|
56 | { |
||
57 | 3 | $result = []; |
|
58 | 3 | foreach ($classes as $classDef) { |
|
59 | 3 | $result[] = $classDef[PreparationProcessorInterface::CLASS_NAME]; |
|
60 | } |
||
61 | |||
62 | 3 | return $result; |
|
63 | } |
||
64 | } |
||
65 |