ClosureLoader::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
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;
21
use Symfony\Component\Config\Loader\Loader;
22
23
/**
24
 * ClosureLoader loads service definitions from a PHP closure.
25
 *
26
 * The Closure has access to the container as its first argument.
27
 *
28
 * @author Divine Niiquaye Ibok <[email protected]>
29
 */
30
class ClosureLoader extends Loader
31
{
32
    private AbstractContainer $container;
33
34 4
    public function __construct(AbstractContainer $container)
35
    {
36 4
        parent::__construct();
37
38 4
        $this->container = $container;
39 4
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function load($resource, string $type = null): void
45
    {
46 2
        $resource($this->container);
47 2
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 2
    public function supports($resource, string $type = null)
53
    {
54 2
        return $resource instanceof \Closure;
55
    }
56
}
57