Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
58.33% |
7 / 12 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ApieConfigFileLocator | |
58.33% |
7 / 12 |
|
66.67% |
2 / 3 |
10.54 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
locate | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
getAllPaths | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | namespace Apie\Common\DependencyInjection; |
3 | |
4 | use Apie\AiInstructor\AiInstructor; |
5 | use Apie\ApieCommonPlugin\ApieCommonPlugin; |
6 | use Apie\Cms\RouteDefinitions\AbstractCmsRouteDefinition; |
7 | use Apie\CmsApiDropdownOption\Lists\DropdownOptionList; |
8 | use Apie\Common\ApieFacade; |
9 | use Apie\Console\ConsoleCommandFactory; |
10 | use Apie\Core\Context\ApieContext; |
11 | use Apie\DoctrineEntityConverter\Factories\PersistenceLayerFactory; |
12 | use Apie\DoctrineEntityDatalayer\DoctrineEntityDatalayer; |
13 | use Apie\Faker\ApieObjectFaker; |
14 | use Apie\HtmlBuilders\FormBuildContext; |
15 | use Apie\Maker\Utils; |
16 | use Apie\McpServer\RunMcpServerCommand; |
17 | use Apie\RestApi\OpenApi\OpenApiGenerator; |
18 | use Apie\SchemaGenerator\ComponentsBuilderFactory; |
19 | use Apie\Serializer\Serializer; |
20 | use Apie\TwigTemplateLayoutRenderer\TwigRenderer; |
21 | use Apie\TypescriptClientBuilder\RouteDefinitions\CodeRouteDefinitionProvider; |
22 | use ReflectionClass; |
23 | use ReflectionException; |
24 | use Symfony\Component\Config\FileLocator; |
25 | |
26 | class ApieConfigFileLocator extends FileLocator |
27 | { |
28 | /** |
29 | * @var array<string, array{class-string<object>, string, class-string<object>}> |
30 | */ |
31 | private array $predefined = [ |
32 | 'ai_instructor.yaml' => [AiInstructor::class, '..', 'Apie\\AiInstructor\\AiInstructorServiceProvider'], |
33 | 'apie_common_plugin.yaml' => [ApieCommonPlugin::class, '..', 'Apie\\ApieCommonPlugin\\GeneratedApieCommonPluginServiceProvider'], |
34 | 'cms.yaml' => [AbstractCmsRouteDefinition::class, '../..', 'Apie\\Cms\\CmsServiceProvider'], |
35 | 'cms_dropdown.yaml' => [DropdownOptionList::class, '../..', 'Apie\\CmsApiDropdownOption\\CmsDropdownServiceProvider'], |
36 | 'common.yaml' => [ApieFacade::class, '..', 'Apie\\Common\\CommonServiceProvider'], |
37 | 'console.yaml' => [ConsoleCommandFactory::class, '..', 'Apie\\Console\\ConsoleServiceProvider'], |
38 | 'core.yaml' => [ApieContext::class, '../..', 'Apie\\Core\\CoreServiceProvider'], |
39 | 'doctrine_entity_converter.yaml' => [PersistenceLayerFactory::class, '../..', 'Apie\\DoctrineEntityConverter\\DoctrineEntityConverterProvider'], |
40 | 'doctrine_entity_datalayer.yaml' => [DoctrineEntityDatalayer::class, '..', 'Apie\\DoctrineEntityDatalayer\\DoctrineEntityDatalayerServiceProvider'], |
41 | 'faker.yaml' => [ApieObjectFaker::class, '..', 'Apie\\Faker\\FakerServiceProvider'], |
42 | 'html_builders.yaml' => [FormBuildContext::class, '..', 'Apie\\HtmlBuilders\\HtmlBuilderServiceProvider'], |
43 | 'maker.yaml' => [Utils::class, '..', 'Apie\\Maker\\MakerServiceProvider'], |
44 | 'mcp_server.yaml' => [RunMcpServerCommand::class, '..', 'Apie\\McpServer\\McpServerServiceProvider'], |
45 | 'rest_api.yaml' => [OpenApiGenerator::class, '../..', 'Apie\\RestApi\\RestApiServiceProvider'], |
46 | 'serializer.yaml' => [Serializer::class, '..', 'Apie\\Serializer\\SerializerServiceProvider'], |
47 | 'schema_generator.yaml' => [ComponentsBuilderFactory::class, '..', 'Apie\\SchemaGenerator\\SchemaGeneratorServiceProvider'], |
48 | 'twig_template_layout_renderer.yaml' => [TwigRenderer::class, '..', 'Apie\\TwigTemplateLayoutRenderer\\TwigTemplateLayoutRendererServiceProvider'], |
49 | 'typescript_client_builder.yaml' => [CodeRouteDefinitionProvider::class, '../..', 'Apie\\TypescriptClientBuilder\\TypescriptClientBuilderServiceProvider'], |
50 | ]; |
51 | |
52 | public function __construct(string|array $paths = []) |
53 | { |
54 | $paths = (array) $paths; |
55 | parent::__construct($paths); |
56 | } |
57 | |
58 | /** |
59 | * @return string|string[] |
60 | */ |
61 | public function locate(string $name, ?string $currentPath = null, bool $first = true): array|string |
62 | { |
63 | if ($currentPath !== null || !isset($this->predefined[$name])) { |
64 | return parent::locate($name, $currentPath, $first); |
65 | } |
66 | $config = $this->predefined[$name]; |
67 | $refl = new ReflectionClass($config[0]); |
68 | return dirname(realpath($refl->getFileName())) . DIRECTORY_SEPARATOR . $config[1] . DIRECTORY_SEPARATOR . $name; |
69 | } |
70 | |
71 | /** |
72 | * @return array<int, array{string, class-string<object>}> |
73 | */ |
74 | public function getAllPaths(): array |
75 | { |
76 | $result = []; |
77 | foreach (array_keys($this->predefined) as $name) { |
78 | try { |
79 | $result[] = [(string) $this->locate($name), $this->predefined[$name][2]]; |
80 | } catch (ReflectionException) { |
81 | } |
82 | } |
83 | return $result; |
84 | } |
85 | } |