|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Zalas\BundleTest\HttpKernel; |
|
5
|
|
|
|
|
6
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
|
10
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
11
|
|
|
|
|
12
|
|
|
class TestKernel extends Kernel |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var KernelConfiguration |
|
16
|
|
|
*/ |
|
17
|
|
|
private $configuration; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(KernelConfiguration $configuration) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($configuration->getEnvironment(), $configuration->isDebug()); |
|
22
|
|
|
|
|
23
|
|
|
$this->configuration = $configuration; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return BundleInterface[] |
|
28
|
|
|
*/ |
|
29
|
|
|
public function registerBundles() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->configuration->getBundles(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getCacheDir() |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->configuration->getCacheDir(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getLogDir() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->configuration->getLogDir(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
|
45
|
|
|
{ |
|
46
|
|
|
$loader->load(function (ContainerBuilder $container) { |
|
47
|
|
|
$this->loadExtensionConfigurations($container); |
|
48
|
|
|
}); |
|
49
|
|
|
$loader->load(function (ContainerBuilder $container) { |
|
50
|
|
|
$this->makeServicesPublic($container); |
|
51
|
|
|
}); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function loadExtensionConfigurations(ContainerBuilder $container) |
|
55
|
|
|
{ |
|
56
|
|
|
foreach ($this->configuration->getAllBundleConfigurations() as $extension => $configuration) { |
|
57
|
|
|
$container->loadFromExtension($extension, $configuration); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private function makeServicesPublic(ContainerBuilder $container) |
|
62
|
|
|
{ |
|
63
|
|
|
$container->addCompilerPass( |
|
64
|
|
|
new class($this->configuration) implements CompilerPassInterface { |
|
65
|
|
|
private $configuration; |
|
66
|
|
|
|
|
67
|
|
|
public function __construct(KernelConfiguration $configuration) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->configuration = $configuration; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function process(ContainerBuilder $container) |
|
73
|
|
|
{ |
|
74
|
|
|
foreach ($this->configuration->getPublicServiceIds() as $serviceId) { |
|
75
|
|
|
if ($container->hasDefinition($serviceId)) { |
|
76
|
|
|
$container->getDefinition($serviceId)->setPublic(true); |
|
77
|
|
|
} |
|
78
|
|
|
if ($container->hasAlias($serviceId)) { |
|
79
|
|
|
$container->getAlias($serviceId)->setPublic(true); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|