Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
48 / 48
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
EngineComponentsBootstrapProvider
100.00% covered (success)
100.00%
47 / 47
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 initialize
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Core\Bootstrap\Provider;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Bootstrap\Configurator\BootstrapEngineContext;
12use App\Core\Bootstrap\Configurator\BootstrapEngineFactory;
13use App\Core\Bootstrap\Configurator\SecurityAndTemplateConfigurator;
14use App\Core\Engine\Domain\DataSource\DynamicDataProviderRegistry;
15use App\Core\Engine\Domain\Repository\MetadataRepositoryInterface;
16use App\Core\Engine\Infrastructure\Repository\SqlAuditRepository;
17use App\Core\Event\SystemEventDispatcher;
18use App\Core\Instance\Application\Service\InstanceContextManager;
19use App\Core\Instance\Application\Service\RemoteInstanceEngineGateway;
20use App\Modules\About\Application\DataSource\AboutLicensesDataProvider;
21use App\Modules\About\Application\DataSource\AboutRequirementsDataProvider;
22use App\Modules\About\Application\Service\SystemDiagnosticsService;
23use App\Modules\About\Infrastructure\Repository\SqlSystemRequirementsRepository;
24use App\Modules\About\Presentation\Api\AboutLicensesApiController;
25use App\Modules\About\Presentation\Api\AboutRequirementsApiController;
26use App\Modules\Currencies\Application\DataSource\CurrenciesDynamicDataProvider;
27use App\Modules\Currencies\Infrastructure\Repository\SqlCurrencyRepository;
28use Nyholm\Psr7\Factory\Psr17Factory;
29use PDO;
30use Yiisoft\Cache\CacheInterface;
31
32/**
33 * Bootstrap provider encapsulating engine context, diagnostics, and engine factory creation.
34 */
35final readonly class EngineComponentsBootstrapProvider
36{
37    public function __construct(
38        private Psr17Factory $psr17Factory
39    ) {
40    }
41
42    /**
43     * Initializes engine context, dynamic data providers, and engine factory.
44     *
45     * @param array<string, mixed> $dependencies
46     * @return array{0: BootstrapEngineFactory, 1: AboutLicensesApiController, 2: AboutRequirementsApiController}
47     */
48    public function initialize(
49        ?PDO $pdo,
50        string $prefix,
51        string $basePath,
52        SecurityAndTemplateConfigurator $sec,
53        array $dependencies
54    ): array {
55        /** @var SqlAuditRepository $auditRepo */
56        $auditRepo = $dependencies['audit_repo'];
57        /** @var MetadataRepositoryInterface $metadataRepo */
58        $metadataRepo = $dependencies['metadata_repo'];
59        /** @var CacheInterface $cache */
60        $cache = $dependencies['cache'];
61        /** @var SystemEventDispatcher $eventDispatcher */
62        $eventDispatcher = $dependencies['event_dispatcher'];
63        /** @var InstanceContextManager $instanceContextManager */
64        $instanceContextManager = $dependencies['instance_context_manager'];
65        /** @var RemoteInstanceEngineGateway $remoteEngineGateway */
66        $remoteEngineGateway = $dependencies['remote_engine_gateway'];
67
68        $aboutLicensesApiController = new AboutLicensesApiController($this->psr17Factory, $pdo, $sec->twig);
69        $sysReqRepo = new SqlSystemRequirementsRepository($pdo, $prefix);
70        $diagnosticsService = new SystemDiagnosticsService($sysReqRepo, $pdo, $basePath);
71        $aboutRequirementsApiController = new AboutRequirementsApiController(
72            $this->psr17Factory,
73            $diagnosticsService
74        );
75
76        $currencyRepo = new SqlCurrencyRepository(
77            $pdo,
78            $prefix,
79            $instanceContextManager,
80            $dependencies['client_pdo'] ?? null
81        );
82
83        $dynamicDataProviders = new DynamicDataProviderRegistry([
84            new AboutLicensesDataProvider(),
85            new AboutRequirementsDataProvider($diagnosticsService),
86            new CurrenciesDynamicDataProvider($currencyRepo),
87        ]);
88
89        $engineContext = new BootstrapEngineContext(
90            $pdo,
91            $prefix,
92            $sec->twig,
93            $eventDispatcher,
94            $auditRepo,
95            $metadataRepo,
96            $cache,
97            $this->psr17Factory,
98            $dynamicDataProviders,
99            $diagnosticsService,
100            $instanceContextManager,
101            $remoteEngineGateway,
102            $dependencies['access_repo'] ?? null,
103            $dependencies['profile_repo'] ?? null,
104            $sec->session,
105            $sec->activeProfile->name,
106            $dependencies['client_pdo'] ?? null,
107            $dependencies['translator'] ?? null
108        );
109        $engineFactory = new BootstrapEngineFactory($engineContext);
110
111        return [$engineFactory, $aboutLicensesApiController, $aboutRequirementsApiController];
112    }
113}