DriverContainer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPFastCGI\FastCGIDaemon\Driver;
6
7
use PHPFastCGI\FastCGIDaemon\DaemonFactoryInterface;
8
9
final class DriverContainer implements DriverContainerInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $drivers;
15
16
    /**
17
     * Constructor.
18
     */
19
    public function __construct()
20
    {
21
        $this->drivers = [
22
            'userland' => [
23
                'object'    => null,
24
                'classPath' => 'PHPFastCGI\FastCGIDaemon\Driver\Userland\UserlandDaemonFactory',
25
            ],
26
        ];
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getFactory(string $driver): DaemonFactoryInterface
33
    {
34
        if (!isset($this->drivers[$driver])) {
35
            throw new \InvalidArgumentException('Unknown driver: '.$driver);
36
        }
37
38
        if (null === $this->drivers[$driver]['object']) {
39
            $class = $this->drivers[$driver]['classPath'];
40
            $this->drivers[$driver]['object'] = new $class();
41
        }
42
43
        return $this->drivers[$driver]['object'];
44
    }
45
}
46