|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zapheus\Bridge\Symfony; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
6
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
7
|
|
|
use Zapheus\Provider\ConfigurationInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Zapheus Kernel |
|
11
|
|
|
* |
|
12
|
|
|
* @package Zapheus |
|
13
|
|
|
* @author Rougin Gutib <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class ZapheusKernel extends Kernel |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var \Zapheus\Provider\ConfigurationInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $configuration; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \Symfony\Component\HttpKernel\Bundle\BundleInterface[] |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $items = array(); |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Initializes the kernel instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface[] $bundles |
|
31
|
|
|
* @param \Zapheus\Provider\ConfigurationInterface $configuration |
|
32
|
|
|
*/ |
|
33
|
3 |
|
public function __construct(array $bundles, ConfigurationInterface $configuration) |
|
34
|
|
|
{ |
|
35
|
3 |
|
$this->configuration = $configuration; |
|
36
|
|
|
|
|
37
|
3 |
|
$parameters = $configuration->get('symfony', array(), true); |
|
38
|
|
|
|
|
39
|
3 |
|
$parameters = $this->defaults((array) $parameters); |
|
40
|
|
|
|
|
41
|
3 |
|
$this->debug = (boolean) $parameters['kernel.debug']; |
|
42
|
|
|
|
|
43
|
3 |
|
$this->environment = $parameters['kernel.environment']; |
|
44
|
|
|
|
|
45
|
3 |
|
$this->rootDir = $parameters['kernel.root_dir']; |
|
46
|
|
|
|
|
47
|
3 |
|
$this->name = $parameters['kernel.name']; |
|
48
|
|
|
|
|
49
|
3 |
|
$this->debug && $this->startTime = microtime(true); |
|
50
|
|
|
|
|
51
|
3 |
|
$this->items = $bundles; |
|
52
|
3 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns an array of bundles to register. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Symfony\Component\HttpKernel\Bundle\BundleInterface[] |
|
58
|
|
|
*/ |
|
59
|
3 |
|
public function registerBundles() |
|
60
|
|
|
{ |
|
61
|
3 |
|
return (array) $this->items; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Loads the container configuration. |
|
66
|
|
|
* |
|
67
|
|
|
* @param \Symfony\Component\Config\Loader\LoaderInterface $loader |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
3 |
|
public function registerContainerConfiguration(LoaderInterface $loader) |
|
71
|
|
|
{ |
|
72
|
3 |
|
$configuration = $this->configuration; |
|
73
|
|
|
|
|
74
|
3 |
|
$loader->load(function ($container) use ($configuration) |
|
75
|
|
|
{ |
|
76
|
3 |
|
$items = $configuration->get('symfony', array(), true); |
|
77
|
|
|
|
|
78
|
3 |
|
foreach ((array) $items as $key => $value) |
|
79
|
|
|
{ |
|
80
|
3 |
|
if (! $container->hasParameter($key)) |
|
81
|
1 |
|
{ |
|
82
|
3 |
|
$container->setParameter($key, $value); |
|
83
|
1 |
|
} |
|
84
|
1 |
|
} |
|
85
|
3 |
|
}); |
|
86
|
3 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns an array of default kernel parameters. |
|
90
|
|
|
* |
|
91
|
|
|
* @param array $config |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
3 |
|
protected function defaults(array $config) |
|
95
|
|
|
{ |
|
96
|
3 |
|
$items = array('kernel.debug' => true); |
|
97
|
|
|
|
|
98
|
3 |
|
$items['kernel.environment'] = 'dev'; |
|
99
|
|
|
|
|
100
|
3 |
|
$items['kernel.root_dir'] = $this->getRootDir(); |
|
101
|
|
|
|
|
102
|
3 |
|
$items['kernel.name'] = $this->getName(); |
|
103
|
|
|
|
|
104
|
3 |
|
foreach ($items as $key => $value) |
|
105
|
|
|
{ |
|
106
|
3 |
|
if (! isset($config[$key])) |
|
107
|
1 |
|
{ |
|
108
|
3 |
|
$config[$key] = $value; |
|
109
|
1 |
|
} |
|
110
|
1 |
|
} |
|
111
|
|
|
|
|
112
|
3 |
|
return $config; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|