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