Passed
Push — master ( b18ae0...059934 )
by Divine Niiquaye
01:50
created

Loader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Biurad opensource projects.
7
 *
8
 * PHP version 7.2 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.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 Biurad\DependencyInjection;
19
20
use Nette;
21
22
/**
23
 * DI container loader.
24
 *
25
 * @author Divine Niiquaye Ibok <[email protected]>
26
 */
27
class Loader extends Nette\DI\ContainerLoader
28
{
29
    /**
30
     * @param string   $class
31
     * @param callable $generator
32
     *
33
     * @return array of (code, file[])
34
     */
35
    protected function generate(string $class, callable $generator): array
36
    {
37
        $compiler = new Compiler(new Builder());
38
        $compiler->setClassName($class);
39
40
        $code = $generator(...[&$compiler]) ?: $compiler->compile();
41
42
        return [
43
            "<?php\n$code",
44
            \serialize($compiler->exportDependencies()),
45
        ];
46
    }
47
}
48