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\RestApi\OpenApi\OpenApiGenerator; |
17 | use Apie\SchemaGenerator\ComponentsBuilderFactory; |
18 | use Apie\Serializer\Serializer; |
19 | use Apie\TwigTemplateLayoutRenderer\TwigRenderer; |
20 | use ReflectionClass; |
21 | use ReflectionException; |
22 | use Symfony\Component\Config\FileLocator; |
23 | |
24 | class ApieConfigFileLocator extends FileLocator |
25 | { |
26 | /** |
27 | * @var array<string, array{class-string<object>, string, class-string<object>}> |
28 | */ |
29 | private array $predefined = [ |
30 | 'ai_instructor.yaml' => [AiInstructor::class, '..', 'Apie\\AiInstructor\\AiInstructorServiceProvider'], |
31 | 'apie_common_plugin.yaml' => [ApieCommonPlugin::class, '..', 'Apie\\ApieCommonPlugin\\GeneratedApieCommonPluginServiceProvider'], |
32 | 'cms.yaml' => [AbstractCmsRouteDefinition::class, '../..', 'Apie\\Cms\\CmsServiceProvider'], |
33 | 'cms_dropdown.yaml' => [DropdownOptionList::class, '../..', 'Apie\\CmsApiDropdownOption\\CmsDropdownServiceProvider'], |
34 | 'common.yaml' => [ApieFacade::class, '..', 'Apie\\Common\\CommonServiceProvider'], |
35 | 'console.yaml' => [ConsoleCommandFactory::class, '..', 'Apie\\Console\\ConsoleServiceProvider'], |
36 | 'core.yaml' => [ApieContext::class, '../..', 'Apie\\Core\\CoreServiceProvider'], |
37 | 'doctrine_entity_converter.yaml' => [PersistenceLayerFactory::class, '../..', 'Apie\\DoctrineEntityConverter\\DoctrineEntityConverterProvider'], |
38 | 'doctrine_entity_datalayer.yaml' => [DoctrineEntityDatalayer::class, '..', 'Apie\\DoctrineEntityDatalayer\\DoctrineEntityDatalayerServiceProvider'], |
39 | 'faker.yaml' => [ApieObjectFaker::class, '..', 'Apie\\Faker\\FakerServiceProvider'], |
40 | 'html_builders.yaml' => [FormBuildContext::class, '..', 'Apie\\HtmlBuilders\\HtmlBuilderServiceProvider'], |
41 | 'maker.yaml' => [Utils::class, '..', 'Apie\\Maker\\MakerServiceProvider'], |
42 | 'rest_api.yaml' => [OpenApiGenerator::class, '../..', 'Apie\\RestApi\\RestApiServiceProvider'], |
43 | 'serializer.yaml' => [Serializer::class, '..', 'Apie\\Serializer\\SerializerServiceProvider'], |
44 | 'schema_generator.yaml' => [ComponentsBuilderFactory::class, '..', 'Apie\\SchemaGenerator\\SchemaGeneratorServiceProvider'], |
45 | 'twig_template_layout_renderer.yaml' => [TwigRenderer::class, '..', 'Apie\\TwigTemplateLayoutRenderer\\TwigTemplateLayoutRendererServiceProvider'], |
46 | ]; |
47 | |
48 | public function __construct(string|array $paths = []) |
49 | { |
50 | $paths = (array) $paths; |
51 | parent::__construct($paths); |
52 | } |
53 | |
54 | /** |
55 | * @return string|string[] |
56 | */ |
57 | public function locate(string $name, ?string $currentPath = null, bool $first = true): array|string |
58 | { |
59 | if ($currentPath !== null || !isset($this->predefined[$name])) { |
60 | return parent::locate($name, $currentPath, $first); |
61 | } |
62 | $config = $this->predefined[$name]; |
63 | $refl = new ReflectionClass($config[0]); |
64 | return dirname(realpath($refl->getFileName())) . DIRECTORY_SEPARATOR . $config[1] . DIRECTORY_SEPARATOR . $name; |
65 | } |
66 | |
67 | /** |
68 | * @return array<int, array{string, class-string<object>}> |
69 | */ |
70 | public function getAllPaths(): array |
71 | { |
72 | $result = []; |
73 | foreach (array_keys($this->predefined) as $name) { |
74 | try { |
75 | $result[] = [(string) $this->locate($name), $this->predefined[$name][2]]; |
76 | } catch (ReflectionException) { |
77 | } |
78 | } |
79 | return $result; |
80 | } |
81 | } |