Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ContainerConfigurator
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 create
100.00% covered (success)
100.00%
8 / 8
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\Configurator;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use Psr\Container\ContainerInterface;
12use Yiisoft\Di\Container;
13use Yiisoft\Di\ContainerConfig;
14
15/**
16 * ContainerConfigurator.
17 *
18 * Configures and constructs the PSR-11 dependency injection container for Yii3 services.
19 *
20 * @package App\Core\Bootstrap\Configurator
21 */
22final readonly class ContainerConfigurator
23{
24    /**
25     * Builds and configures the DI container with definitions and optional providers.
26     *
27     * @param array<string, mixed> $definitions Service definitions map.
28     * @param array<int, class-string<\Yiisoft\Di\ServiceProviderInterface>
29     *     |\Yiisoft\Di\ServiceProviderInterface> $providers Service providers.
30     * @return ContainerInterface Configured PSR-11 container.
31     */
32    public static function create(array $definitions = [], array $providers = []): ContainerInterface
33    {
34        $filteredDefinitions = array_filter(
35            $definitions,
36            static fn(mixed $val): bool => $val !== null
37        );
38
39        $config = ContainerConfig::create()
40            ->withDefinitions($filteredDefinitions)
41            ->withProviders($providers);
42
43        return new Container($config);
44    }
45}