Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
95 / 95 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
Configuration | |
100.00% |
95 / 95 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
addCmsOptions | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
addApiOptions | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getConfigTreeBuilder | |
100.00% |
95 / 95 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | namespace Apie\Common\Config; |
3 | |
4 | use Apie\DoctrineEntityDatalayer\IndexStrategy\DirectIndexStrategy; |
5 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
6 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
8 | |
9 | /** |
10 | * Configuration |
11 | */ |
12 | abstract class Configuration implements ConfigurationInterface |
13 | { |
14 | private const ENABLE_CONFIGS = [ |
15 | 'enable_ai_instructor' => 'Apie\AiInstructor\AiInstructor', |
16 | 'enable_common_plugin' => 'Apie\ApieCommonPlugin\ApieCommonPlugin', |
17 | 'enable_cms' => 'Apie\Cms\RouteDefinitions\CmsRouteDefinitionProvider', |
18 | 'enable_cms_dropdown' => 'Apie\CmsApiDropdownOption\RouteDefinitions\DropdownOptionsForExistingObjectRouteDefinition', |
19 | 'enable_doctrine_entity_converter' => 'Apie\DoctrineEntityConverter\OrmBuilder', |
20 | 'enable_doctrine_entity_datalayer' => 'Apie\DoctrineEntityDatalayer\DoctrineEntityDatalayer', |
21 | 'enable_faker' => 'Apie\Faker\ApieObjectFaker', |
22 | 'enable_maker' => 'Apie\Maker\Utils', |
23 | 'enable_rest_api' => 'Apie\RestApi\OpenApi\OpenApiGenerator', |
24 | 'enable_console' => 'Apie\Console\ConsoleCommandFactory', |
25 | 'enable_twig_template_layout_renderer' => 'Apie\TwigTemplateLayoutRenderer\TwigRenderer', |
26 | ]; |
27 | |
28 | abstract protected function addCmsOptions(ArrayNodeDefinition $arrayNode): void; |
29 | |
30 | abstract protected function addApiOptions(ArrayNodeDefinition $arrayNode): void; |
31 | |
32 | public function getConfigTreeBuilder(): TreeBuilder |
33 | { |
34 | $treeBuilder = new TreeBuilder('apie'); |
35 | |
36 | $children = $treeBuilder->getRootNode()->children(); |
37 | $children->booleanNode('enable_core')->defaultValue(true)->end(); |
38 | $children->scalarNode('encryption_key')->end(); |
39 | $cmsConfig = $children->arrayNode('cms'); |
40 | $cmsConfig->children() |
41 | ->scalarNode('base_url')->defaultValue('/cms')->end() |
42 | ->arrayNode('asset_folders')->scalarPrototype()->end() |
43 | ->end(); |
44 | $this->addCmsOptions($cmsConfig); |
45 | $apiConfig = $children->arrayNode('rest_api'); |
46 | $apiConfig->children() |
47 | ->scalarNode('base_url')->defaultValue('/api')->end() |
48 | ->end(); |
49 | $this->addApiOptions($apiConfig); |
50 | |
51 | $aiConfig = $children->arrayNode('ai'); |
52 | $aiConfig->children() |
53 | ->scalarNode('base_url')->defaultValue('https://api.openai.com/v1')->end() |
54 | ->scalarNode('api_key')->defaultValue('no-value')->end() |
55 | ->end(); |
56 | $children->arrayNode('datalayers') |
57 | ->children() |
58 | ->scalarNode('default_datalayer')->isRequired()->end() |
59 | ->arrayNode('context_mapping') |
60 | ->useAttributeAsKey('name') |
61 | ->arrayPrototype() |
62 | ->isRequired() |
63 | ->children() |
64 | ->scalarNode('default_datalayer')->isRequired()->end() |
65 | ->arrayNode('entity_mapping') |
66 | ->useAttributeAsKey('class') |
67 | ->scalarPrototype() |
68 | ->end() |
69 | ->end() |
70 | ->end() |
71 | ->end() |
72 | ->end() |
73 | ->end() |
74 | ->end() |
75 | ->arrayNode('doctrine') |
76 | ->children() |
77 | ->arrayNode('indexing') |
78 | ->children() |
79 | ->enumNode('type')->values(['direct', 'late', 'background', 'custom'])->defaultValue('direct')->end() |
80 | ->scalarNode('service')->defaultValue(DirectIndexStrategy::class)->end() |
81 | ->end() |
82 | ->end() |
83 | ->scalarNode('build_once')->defaultValue(false)->end() |
84 | ->scalarNode('run_migrations')->defaultValue(true)->end() |
85 | ->arrayNode('connection_params') |
86 | ->defaultValue(['driver' => 'pdo_sqlite']) |
87 | ->useAttributeAsKey('class') |
88 | ->scalarPrototype() |
89 | ->end() |
90 | ->end() |
91 | ->end() |
92 | ->end() |
93 | ->arrayNode('storage') |
94 | ->arrayPrototype() |
95 | ->children() |
96 | ->scalarNode('class')->isRequired()->end() |
97 | ->arrayNode('options')->defaultValue([]) |
98 | ->scalarPrototype() |
99 | ->end() |
100 | ->end() |
101 | ->end() |
102 | ->end() |
103 | ->end() |
104 | ->arrayNode('maker') |
105 | ->children() |
106 | ->scalarNode('target_path')->defaultValue(false)->end() |
107 | ->scalarNode('target_namespace')->defaultValue('App\Apie')->end() |
108 | ->end() |
109 | ->end() |
110 | ->arrayNode('bounded_contexts') |
111 | ->useAttributeAsKey('name') |
112 | ->arrayPrototype() |
113 | ->children() |
114 | ->scalarNode('entities_folder')->isRequired()->end() |
115 | ->scalarNode('entities_namespace')->isRequired()->end() |
116 | ->scalarNode('actions_folder')->isRequired()->end() |
117 | ->scalarNode('actions_namespace')->isRequired()->end() |
118 | ->end() |
119 | ->end() |
120 | ->end() |
121 | ->arrayNode('scan_bounded_contexts') |
122 | ->children() |
123 | ->scalarNode('search_path')->end() |
124 | ->scalarNode('search_namespace')->end() |
125 | ->end() |
126 | ->end(); |
127 | $childNode = $treeBuilder->getRootNode()->children(); |
128 | foreach (self::ENABLE_CONFIGS as $configKey => $classNameToExist) { |
129 | $childNode->booleanNode($configKey)->defaultValue(class_exists($classNameToExist)); |
130 | } |
131 | return $treeBuilder; |
132 | } |
133 | } |