Test Failed
Push — master ( fd2f49...f2c22d )
by Yaroslav
07:55
created

Kernel::loadRoutes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 registerContainerConfiguration(LoaderInterface $loader)
62
    {
63
        $confDir = __DIR__.'/config';
64
65
        $loader->load($confDir.'/*'.self::CONFIG_EXTS, 'glob');
66
67
        $loader->load(function (ContainerBuilder $container) {
68
            foreach ($this->testConfigs as $extension => $config) {
69
                $container->loadFromExtension($extension, $config);
70
            }
71
72
            $container->loadFromExtension('framework', array(
73
                'router' => array(
74
                    'resource' => 'kernel::loadRoutes',
75
                    'type' => 'service',
76
                ),
77
            ));
78
        });
79
    }
80
81
    public function loadRoutes(LoaderInterface $loader)
82
    {
83
        $routes = new RouteCollectionBuilder($loader);
84
85
        $confDir = __DIR__.'/config';
86
        $routes->import($confDir.'/routes/routes.yaml');
87
88
        foreach ($this->routeResources as $routeResource) {
89
            $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

89
            $routes->import(/** @scrutinizer ignore-type */ ...$routeResource);
Loading history...
90
        }
91
92
        return $routes->build();
93
    }
94
95
    /*
96
    protected function build(ContainerBuilder $container)
97
    {
98
        $container->register('logger', \Psr\Log\NullLogger::class);
99
    }
100
    */
101
}
102