Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
97 / 97 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Configuration | |
100.00% |
97 / 97 |
|
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% |
97 / 97 |
|
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_mcp_server' => 'Apie\McpServer\RunMcpServerCommand', |
| 24 | 'enable_rest_api' => 'Apie\RestApi\OpenApi\OpenApiGenerator', |
| 25 | 'enable_console' => 'Apie\Console\ConsoleCommandFactory', |
| 26 | 'enable_twig_template_layout_renderer' => 'Apie\TwigTemplateLayoutRenderer\TwigRenderer', |
| 27 | 'enable_typescript_client_builder' => 'Apie\TypescriptClientBuilder\RouteDefinitions\CodeRouteDefinitionProvider', |
| 28 | 'enable_webdav' => 'Apie\Webdav\Controller\WebdavController', |
| 29 | ]; |
| 30 | |
| 31 | abstract protected function addCmsOptions(ArrayNodeDefinition $arrayNode): void; |
| 32 | |
| 33 | abstract protected function addApiOptions(ArrayNodeDefinition $arrayNode): void; |
| 34 | |
| 35 | public function getConfigTreeBuilder(): TreeBuilder |
| 36 | { |
| 37 | $treeBuilder = new TreeBuilder('apie'); |
| 38 | |
| 39 | $children = $treeBuilder->getRootNode()->children(); |
| 40 | $children->booleanNode('enable_core')->defaultValue(true)->end(); |
| 41 | $children->scalarNode('encryption_key')->end(); |
| 42 | $cmsConfig = $children->arrayNode('cms'); |
| 43 | $cmsConfig->children() |
| 44 | ->scalarNode('base_url')->defaultValue('/cms')->end() |
| 45 | ->arrayNode('asset_folders')->scalarPrototype()->end() |
| 46 | ->end(); |
| 47 | $this->addCmsOptions($cmsConfig); |
| 48 | $apiConfig = $children->arrayNode('rest_api'); |
| 49 | $apiConfig->children() |
| 50 | ->scalarNode('base_url')->defaultValue('/api')->end() |
| 51 | ->end(); |
| 52 | $this->addApiOptions($apiConfig); |
| 53 | |
| 54 | $aiConfig = $children->arrayNode('ai') |
| 55 | ->addDefaultsIfNotSet(); |
| 56 | $aiConfig->children() |
| 57 | ->scalarNode('base_url')->defaultValue('https://api.openai.com/v1')->end() |
| 58 | ->scalarNode('api_key')->defaultValue('no-value')->end() |
| 59 | ->end(); |
| 60 | $children->arrayNode('datalayers') |
| 61 | ->children() |
| 62 | ->scalarNode('default_datalayer')->isRequired()->end() |
| 63 | ->arrayNode('context_mapping') |
| 64 | ->useAttributeAsKey('name') |
| 65 | ->arrayPrototype() |
| 66 | ->isRequired() |
| 67 | ->children() |
| 68 | ->scalarNode('default_datalayer')->isRequired()->end() |
| 69 | ->arrayNode('entity_mapping') |
| 70 | ->useAttributeAsKey('class') |
| 71 | ->scalarPrototype() |
| 72 | ->end() |
| 73 | ->end() |
| 74 | ->end() |
| 75 | ->end() |
| 76 | ->end() |
| 77 | ->end() |
| 78 | ->end() |
| 79 | ->arrayNode('doctrine') |
| 80 | ->children() |
| 81 | ->arrayNode('indexing') |
| 82 | ->children() |
| 83 | ->enumNode('type')->values(['direct', 'late', 'background', 'custom'])->defaultValue('direct')->end() |
| 84 | ->scalarNode('service')->defaultValue(DirectIndexStrategy::class)->end() |
| 85 | ->end() |
| 86 | ->end() |
| 87 | ->scalarNode('build_once')->defaultValue(false)->end() |
| 88 | ->scalarNode('run_migrations')->defaultValue(true)->end() |
| 89 | ->arrayNode('connection_params') |
| 90 | ->defaultValue(['driver' => 'pdo_sqlite']) |
| 91 | ->useAttributeAsKey('class') |
| 92 | ->scalarPrototype() |
| 93 | ->end() |
| 94 | ->end() |
| 95 | ->end() |
| 96 | ->end() |
| 97 | ->arrayNode('storage') |
| 98 | ->arrayPrototype() |
| 99 | ->children() |
| 100 | ->scalarNode('class')->isRequired()->end() |
| 101 | ->arrayNode('options')->defaultValue([]) |
| 102 | ->scalarPrototype() |
| 103 | ->end() |
| 104 | ->end() |
| 105 | ->end() |
| 106 | ->end() |
| 107 | ->end() |
| 108 | ->arrayNode('maker') |
| 109 | ->children() |
| 110 | ->scalarNode('target_path')->defaultValue(false)->end() |
| 111 | ->scalarNode('target_namespace')->defaultValue('App\Apie')->end() |
| 112 | ->end() |
| 113 | ->end() |
| 114 | ->arrayNode('bounded_contexts') |
| 115 | ->useAttributeAsKey('name') |
| 116 | ->arrayPrototype() |
| 117 | ->children() |
| 118 | ->scalarNode('entities_folder')->isRequired()->end() |
| 119 | ->scalarNode('entities_namespace')->isRequired()->end() |
| 120 | ->scalarNode('actions_folder')->isRequired()->end() |
| 121 | ->scalarNode('actions_namespace')->isRequired()->end() |
| 122 | ->end() |
| 123 | ->end() |
| 124 | ->end() |
| 125 | ->arrayNode('scan_bounded_contexts') |
| 126 | ->children() |
| 127 | ->scalarNode('search_path')->end() |
| 128 | ->scalarNode('search_namespace')->end() |
| 129 | ->end() |
| 130 | ->end(); |
| 131 | $childNode = $treeBuilder->getRootNode()->children(); |
| 132 | foreach (self::ENABLE_CONFIGS as $configKey => $classNameToExist) { |
| 133 | $childNode->booleanNode($configKey)->defaultValue(class_exists($classNameToExist)); |
| 134 | } |
| 135 | $childNode->scalarNode('remote_mcp_path')->defaultValue(null)->end(); |
| 136 | return $treeBuilder; |
| 137 | } |
| 138 | } |