1 | <?php namespace Limoncello\Application\Packages\Data; |
||
30 | abstract class DataSettings implements SettingsInterface |
||
31 | { |
||
32 | use ClassIsTrait, CheckCallableTrait; |
||
33 | |||
34 | /** Settings key */ |
||
35 | const KEY_MODELS_FOLDER = 0; |
||
36 | |||
37 | /** Settings key */ |
||
38 | const KEY_MODELS_FILE_MASK = self::KEY_MODELS_FOLDER + 1; |
||
39 | |||
40 | /** Settings key */ |
||
41 | const KEY_MIGRATIONS_FOLDER = self::KEY_MODELS_FILE_MASK + 1; |
||
42 | |||
43 | /** Settings key */ |
||
44 | const KEY_MIGRATIONS_LIST_FILE = self::KEY_MIGRATIONS_FOLDER + 1; |
||
45 | |||
46 | /** Settings key */ |
||
47 | const KEY_SEEDS_FOLDER = self::KEY_MIGRATIONS_LIST_FILE + 1; |
||
48 | |||
49 | /** Settings key */ |
||
50 | const KEY_SEEDS_LIST_FILE = self::KEY_SEEDS_FOLDER + 1; |
||
51 | |||
52 | /** Settings key */ |
||
53 | const KEY_SEED_INIT = self::KEY_SEEDS_LIST_FILE + 1; |
||
54 | |||
55 | /** Settings key */ |
||
56 | const KEY_MODELS_SCHEMA_INFO = self::KEY_SEED_INIT + 1; |
||
57 | |||
58 | /** Settings key */ |
||
59 | protected const KEY_LAST = self::KEY_MODELS_SCHEMA_INFO; |
||
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | 2 | final public function get(array $appConfig): array |
|
65 | { |
||
66 | 2 | $defaults = $this->getSettings(); |
|
67 | |||
68 | 2 | $modelsFolder = $defaults[static::KEY_MODELS_FOLDER] ?? null; |
|
69 | 2 | $modelsFileMask = $defaults[static::KEY_MODELS_FILE_MASK] ?? null; |
|
70 | 2 | $migrationsFolder = $defaults[static::KEY_MIGRATIONS_FOLDER] ?? null; |
|
71 | 2 | $migrationsListFile = $defaults[static::KEY_MIGRATIONS_LIST_FILE] ?? null; |
|
72 | 2 | $seedsFolder = $defaults[static::KEY_SEEDS_FOLDER] ?? null; |
|
73 | 2 | $seedsListFile = $defaults[static::KEY_SEEDS_LIST_FILE] ?? null; |
|
74 | |||
75 | 2 | assert( |
|
76 | 2 | $modelsFolder !== null && empty(glob($modelsFolder)) === false, |
|
77 | 2 | "Invalid Models folder `$modelsFolder`." |
|
78 | ); |
||
79 | 2 | assert(empty($modelsFileMask) === false, "Invalid Models file mask `$modelsFileMask`."); |
|
80 | 2 | assert( |
|
81 | 2 | $migrationsFolder !== null && empty(glob($migrationsFolder)) === false, |
|
82 | 2 | "Invalid Migrations folder `$migrationsFolder`." |
|
83 | ); |
||
84 | 2 | assert(file_exists($migrationsListFile) === true, "Invalid Migrations file `$migrationsListFile`."); |
|
85 | 2 | assert( |
|
86 | 2 | $seedsFolder !== null && empty(glob($seedsFolder)) === false, |
|
87 | 2 | "Invalid Seeds folder `$seedsFolder`." |
|
88 | ); |
||
89 | 2 | assert(file_exists($seedsListFile) === true, "Invalid Seeds file `$seedsListFile`."); |
|
90 | |||
91 | 2 | $modelsPath = $modelsFolder . DIRECTORY_SEPARATOR . $modelsFileMask; |
|
92 | |||
93 | 2 | $seedInit = $defaults[static::KEY_SEED_INIT] ?? null; |
|
94 | 2 | assert( |
|
95 | ( |
||
96 | 2 | $seedInit === null || |
|
97 | 2 | $this->checkPublicStaticCallable($seedInit, [ContainerInterface::class, 'string']) === true |
|
98 | ), |
||
99 | 2 | 'Seed init should be either `null` or static callable.' |
|
100 | ); |
||
101 | |||
102 | 2 | $defaults[static::KEY_MODELS_SCHEMA_INFO] = $this->getModelsSchemaInfo($modelsPath); |
|
103 | |||
104 | 2 | return $defaults; |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * @return array |
||
109 | */ |
||
110 | 2 | protected function getSettings(): array |
|
117 | |||
118 | /** |
||
119 | * @param string $modelsPath |
||
120 | * |
||
121 | * @return array |
||
122 | * |
||
123 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
||
124 | */ |
||
125 | 2 | private function getModelsSchemaInfo(string $modelsPath): array |
|
207 | } |
||
208 |