1 | <?php |
||
25 | class DocumentsLocator implements LocatorInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var \Psr\Log\LoggerInterface |
||
29 | */ |
||
30 | private $logger; |
||
31 | |||
32 | /** |
||
33 | * @var \Spiral\ODM\Schemas\SchemaInterface[] |
||
34 | */ |
||
35 | private $schemas; |
||
36 | |||
37 | /** |
||
38 | * @var \Spiral\ODM\Schemas\SchemaBuilder |
||
39 | */ |
||
40 | private $builder; |
||
41 | |||
42 | /** |
||
43 | * DocumentsLocator constructor. |
||
44 | * |
||
45 | * @param LoggerInterface $logger |
||
46 | * @param ODM $odm |
||
47 | */ |
||
48 | public function __construct(LoggerInterface $logger, ODM $odm) |
||
55 | |||
56 | /** |
||
57 | * @inheritdoc |
||
58 | */ |
||
59 | public function locate(): array |
||
77 | |||
78 | /** |
||
79 | * @param DocumentSchema $schema |
||
80 | * @return array |
||
81 | */ |
||
82 | private function scan(DocumentSchema $schema): array |
||
83 | { |
||
84 | $fields = $this->processFields($schema->getFields()); |
||
85 | $mutators = $this->processMutators($schema->getMutators()); |
||
86 | $compositions = $this->processCompositions($schema->getCompositions($this->builder)); |
||
87 | |||
88 | $properties = array_merge($fields, $mutators, $compositions); |
||
89 | $docs = []; |
||
90 | foreach ($properties as $name => $type) { |
||
91 | $docs[] = new ClassProperty($name, $type); |
||
92 | } |
||
93 | |||
94 | return $docs; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @param array $fields |
||
99 | * @return array |
||
100 | */ |
||
101 | private function processFields(array $fields): array |
||
117 | |||
118 | /** |
||
119 | * @param array $mutators |
||
120 | * @return array |
||
121 | */ |
||
122 | private function processMutators(array $mutators): array |
||
132 | |||
133 | /** |
||
134 | * @param array $compositions |
||
135 | * @return array |
||
136 | */ |
||
137 | private function processCompositions(array $compositions): array |
||
162 | } |
||
163 |