Passed
Push — master ( abee1f...edc958 )
by Kirill
03:08
created

PhpLoader::loadFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Config\Loader;
13
14
use Psr\Container\ContainerInterface;
15
use Spiral\Config\Exception\LoaderException;
16
use Spiral\Core\ContainerScope;
17
18
/**
19
 * Loads PHP files inside container scope.
20
 */
21
final class PhpLoader implements FileLoaderInterface
22
{
23
    /** @var ContainerInterface */
24
    private $container;
25
26
    /**
27
     * @param ContainerInterface $container
28
     */
29
    public function __construct(ContainerInterface $container)
30
    {
31
        $this->container = $container;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function loadFile(string $section, string $filename): array
38
    {
39
        try {
40
            return ContainerScope::runScope($this->container, function () use ($filename) {
41
                return (require $filename);
42
            });
43
        } catch (\Throwable $e) {
44
            throw new LoaderException($e->getMessage(), $e->getCode(), $e);
45
        }
46
    }
47
}
48