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