Passed
Push — master ( 6a389c...42f43f )
by Divine Niiquaye
01:03 queued 12s
created

ProviderLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2021 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\DI\Loader;
19
20
use Rade\DI\{AbstractContainer, Container, ContainerBuilder};
21
use Rade\DI\Services\ServiceProviderInterface;
22
23
/**
24
 * This class delegates container service providers.
25
 * Setting service provider's config, keys should always begin with service provider's class name.
26
 *
27
 * @author Divine Niiquaye Ibok <[email protected]>
28
 */
29
class ProviderLoader
30
{
31
    /** @var ServiceProviderInterface[] */
32
    private array $providers;
33
34
    private array $config;
35
36
    /**
37
     * @param ServiceProviderInterface[] $providers
38
     */
39 2
    public function __construct(array $providers, array $config = [])
40
    {
41 2
        $this->providers = $providers;
42 2
        $this->config = $config;
43 2
    }
44
45
    /**
46
     * Loads service providers will one configuration.
47
     *
48
     * @param Container|ContainerBuilder $container
49
     */
50 2
    public function load(AbstractContainer $container): void
51
    {
52 2
        foreach ($this->providers as $provider) {
53 2
            $container->register($provider, $this->config[\get_class($provider)] ?? []);
54
        }
55 2
    }
56
}
57