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); |
|
|
|
|
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
|
|
|
|