Test Failed
Push — master ( 36d70f...df7538 )
by Yaroslav
08:47
created

Kernel::getProjectDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Tests\Functional\app;
12
13
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
14
use Symfony\Component\Config\Loader\LoaderInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\Routing\RouteCollectionBuilder;
17
18
/**
19
 * @author Yaroslav Honcharuk <[email protected]>
20
 */
21
class Kernel extends BaseKernel
22
{
23
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
24
25
    private $testVarDir;
26
    private $testBundles;
27
    private $testConfigs;
28
    private $routeResources;
29
30
    public function __construct($varDir, $bundles, $configs, $routeResources, $environment, $debug)
31
    {
32
        $this->testVarDir = $varDir;
33
        $this->testBundles = $bundles;
34
        $this->testConfigs = $configs;
35
        $this->routeResources = $routeResources;
36
37
        parent::__construct($environment, $debug);
38
    }
39
40
    public function registerBundles()
41
    {
42
        $bundles = [];
43
44
        foreach ($this->testBundles as $class) {
45
            $bundles[] = new $class();
46
        }
47
48
        return $bundles;
49
    }
50
51
    public function getCacheDir()
52
    {
53
        return $this->testVarDir.'/cache/'.$this->environment;
54
    }
55
56
    public function getLogDir()
57
    {
58
        return $this->testVarDir.'/logs';
59
    }
60
61
    public function getProjectDir()
62
    {
63
        return __DIR__;
64
    }
65
66
    public function registerContainerConfiguration(LoaderInterface $loader)
67
    {
68
        $confDir = __DIR__.'/config';
69
70
        $loader->load($confDir.'/*'.self::CONFIG_EXTS, 'glob');
71
72
        $loader->load(function (ContainerBuilder $container) {
73
            foreach ($this->testConfigs as $extension => $config) {
74
                $container->loadFromExtension($extension, $config);
75
            }
76
77
            $service = static::MAJOR_VERSION < 4 ? 'kernel:loadRoutes' : 'kernel::loadRoutes';
78
79
            $container->loadFromExtension('framework', array(
80
                'router' => array(
81
                    'resource' => $service,
82
                    'type' => 'service',
83
                ),
84
            ));
85
        });
86
    }
87
88
    public function loadRoutes(LoaderInterface $loader)
89
    {
90
        $routes = new RouteCollectionBuilder($loader);
91
92
        $confDir = __DIR__.'/config';
93
        $routes->import($confDir.'/routes/routes.yaml');
94
95
        foreach ($this->routeResources as $routeResource) {
96
            $routes->import(...$routeResource);
0 ignored issues
show
Bug introduced by
$routeResource is expanded, but the parameter $resource of Symfony\Component\Routin...ectionBuilder::import() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

96
            $routes->import(/** @scrutinizer ignore-type */ ...$routeResource);
Loading history...
97
        }
98
99
        return $routes->build();
100
    }
101
102
    /*
103
    protected function build(ContainerBuilder $container)
104
    {
105
        $container->register('logger', \Psr\Log\NullLogger::class);
106
    }
107
    */
108
}
109