Total Complexity | 8 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
22 | final class SyncTables implements GeneratorInterface |
||
23 | { |
||
24 | // Readonly tables must be included form the sync with database |
||
25 | public const READONLY_SCHEMA = 'readonlySchema'; |
||
26 | |||
27 | /** |
||
28 | * @param Registry $registry |
||
29 | * |
||
30 | * @return Registry |
||
31 | * |
||
32 | * @throws SyncException |
||
33 | */ |
||
34 | public function run(Registry $registry): Registry |
||
35 | { |
||
36 | foreach ($this->getRegistryDbList($registry) as $dbName) { |
||
37 | $reflector = new Reflector(); |
||
38 | |||
39 | foreach ($registry as $regEntity) { |
||
40 | if ($registry->getDatabase($regEntity) !== $dbName) { |
||
41 | continue; |
||
42 | } |
||
43 | $reflector->addTable($registry->getTableSchema($regEntity)); |
||
44 | } |
||
45 | |||
46 | try { |
||
47 | $reflector->run(); |
||
48 | } catch (\Throwable $e) { |
||
49 | throw new SyncException($e->getMessage(), $e->getCode(), $e); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | return $registry; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param Registry $registry |
||
58 | * |
||
59 | * @return array |
||
60 | */ |
||
61 | private function getRegistryDbList(Registry $registry): array |
||
74 | } |
||
75 | } |
||
76 |