1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is a part of Sculpin. |
5
|
|
|
* |
6
|
|
|
* (c) Dragonfly Development Inc. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Symplify\PHP7_Sculpin\Bundle\SculpinBundle\HttpKernel; |
13
|
|
|
|
14
|
|
|
use Symplify\PHP7_Sculpin\Bundle\ContentTypesBundle\SculpinContentTypesBundle; |
15
|
|
|
use Symplify\PHP7_Sculpin\Bundle\MarkdownBundle\SculpinMarkdownBundle; |
16
|
|
|
use Symplify\PHP7_Sculpin\Bundle\MarkdownTwigCompatBundle\SculpinMarkdownTwigCompatBundle; |
17
|
|
|
use Symplify\PHP7_Sculpin\Bundle\PaginationBundle\SculpinPaginationBundle; |
18
|
|
|
use Symplify\PHP7_Sculpin\Bundle\SculpinBundle\SculpinBundle; |
19
|
|
|
use Symplify\PHP7_Sculpin\Bundle\StandaloneBundle\SculpinStandaloneBundle; |
20
|
|
|
use Symplify\PHP7_Sculpin\Bundle\TwigBundle\SculpinTwigBundle; |
21
|
|
|
use Symfony\Component\Config\FileLocator; |
22
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
23
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
24
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
25
|
|
|
use Symplify\DefaultAutowire\SymplifyDefaultAutowireBundle; |
26
|
|
|
|
27
|
|
|
abstract class AbstractKernel extends Kernel |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $projectDir; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function __construct(string $environment, string $debug, string $projectDir = null) |
38
|
|
|
{ |
39
|
|
|
if ($projectDir) { |
|
|
|
|
40
|
|
|
$this->projectDir = $projectDir; |
41
|
|
|
$this->rootDir = $projectDir.'/app'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
parent::__construct($environment, $debug); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
protected function getKernelParameters() |
51
|
|
|
{ |
52
|
|
|
if (null === $this->projectDir) { |
53
|
|
|
$this->projectDir = dirname($this->rootDir); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return array_merge(parent::getKernelParameters(), [ |
57
|
|
|
'sculpin.project_dir' => $this->projectDir, |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function registerBundles() |
65
|
|
|
{ |
66
|
|
|
$bundles = [ |
67
|
|
|
new SymplifyDefaultAutowireBundle(), |
68
|
|
|
new SculpinStandaloneBundle(), |
69
|
|
|
new SculpinMarkdownBundle(), |
70
|
|
|
new SculpinMarkdownTwigCompatBundle(), |
71
|
|
|
new SculpinPaginationBundle(), |
72
|
|
|
new SculpinBundle(), |
73
|
|
|
new SculpinTwigBundle(), |
74
|
|
|
new SculpinContentTypesBundle(), |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
foreach ($this->getAdditionalSculpinBundles() as $class) { |
78
|
|
|
$bundles[] = new $class(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $bundles; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
88
|
|
|
{ |
89
|
|
|
// Load defaults. |
90
|
|
|
$loader->load(__DIR__.'/../Resources/config/kernel.yml'); |
91
|
|
|
|
92
|
|
|
if (file_exists($file = $this->rootDir.'/config/sculpin_kernel.yml')) { |
93
|
|
|
$loader->load($file); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function boot() |
101
|
|
|
{ |
102
|
|
|
if (true === $this->booted) { |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
parent::boot(); |
107
|
|
|
|
108
|
|
|
$this->container->compile(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* {@inheritdoc} |
113
|
|
|
*/ |
114
|
|
|
protected function buildContainer() |
115
|
|
|
{ |
116
|
|
|
$container = $this->getContainerBuilder(); |
117
|
|
|
$container->addObjectResource($this); |
118
|
|
|
$this->prepareContainer($container); |
119
|
|
|
|
120
|
|
|
if (file_exists($this->rootDir.'/config/sculpin_services.yml')) { |
121
|
|
|
$loader = new YamlFileLoader($container, new FileLocator($this->rootDir.'/config')); |
122
|
|
|
$loader->load('sculpin_services.yml'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) { |
|
|
|
|
126
|
|
|
$container->merge($cont); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $container; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* {@inheritdoc} |
134
|
|
|
*/ |
135
|
|
|
protected function initializeContainer() |
136
|
|
|
{ |
137
|
|
|
$container = $this->buildContainer(); |
138
|
|
|
$container->set('kernel', $this); |
139
|
|
|
$this->container = $container; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
abstract protected function getAdditionalSculpinBundles() : array; |
143
|
|
|
} |
144
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: