|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
6
|
|
|
use Shopware\Core\DevOps\Environment\EnvironmentHelper; |
|
7
|
|
|
use Shopware\Core\Framework\Adapter\Database\MySQLFactory; |
|
8
|
|
|
use Shopware\Core\Framework\Api\Controller\FallbackController; |
|
9
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
10
|
|
|
use Shopware\Core\Framework\Plugin\KernelPluginLoader\KernelPluginLoader; |
|
11
|
|
|
use Shopware\Core\Framework\Util\VersionParser; |
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
|
13
|
|
|
use Symfony\Component\Config\ConfigCache; |
|
14
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle; |
|
19
|
|
|
use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
|
20
|
|
|
use Symfony\Component\HttpKernel\Kernel as HttpKernel; |
|
|
|
|
|
|
21
|
|
|
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; |
|
22
|
|
|
use Symfony\Component\Routing\Route; |
|
23
|
|
|
|
|
24
|
|
|
#[Package('core')] |
|
25
|
|
|
class Kernel extends HttpKernel |
|
26
|
|
|
{ |
|
27
|
|
|
use MicroKernelTrait; |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
final public const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string Fallback version if nothing is provided via kernel constructor |
|
33
|
|
|
*/ |
|
34
|
|
|
final public const SHOPWARE_FALLBACK_VERSION = '6.5.9999999.9999999-dev'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var Connection|null |
|
38
|
|
|
*/ |
|
39
|
|
|
protected static $connection; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var KernelPluginLoader |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $pluginLoader; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $shopwareVersion; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var string|null |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $shopwareVersionRevision; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var string|null |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $projectDir; |
|
60
|
|
|
|
|
61
|
|
|
private bool $rebooting = false; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritdoc} |
|
65
|
|
|
*/ |
|
66
|
|
|
public function __construct( |
|
67
|
|
|
string $environment, |
|
68
|
|
|
bool $debug, |
|
69
|
|
|
KernelPluginLoader $pluginLoader, |
|
70
|
|
|
private string $cacheId, |
|
71
|
|
|
?string $version = self::SHOPWARE_FALLBACK_VERSION, |
|
72
|
|
|
?Connection $connection = null, |
|
73
|
|
|
?string $projectDir = null |
|
74
|
|
|
) { |
|
75
|
|
|
date_default_timezone_set('UTC'); |
|
76
|
|
|
|
|
77
|
|
|
parent::__construct($environment, $debug); |
|
78
|
|
|
self::$connection = $connection; |
|
79
|
|
|
|
|
80
|
|
|
$this->pluginLoader = $pluginLoader; |
|
81
|
|
|
|
|
82
|
|
|
$version = VersionParser::parseShopwareVersion($version); |
|
83
|
|
|
$this->shopwareVersion = $version['version']; |
|
84
|
|
|
$this->shopwareVersionRevision = $version['revision']; |
|
85
|
|
|
$this->projectDir = $projectDir; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return iterable<BundleInterface> |
|
90
|
|
|
*/ |
|
91
|
|
|
public function registerBundles(): iterable |
|
92
|
|
|
{ |
|
93
|
|
|
/** @var array<class-string<Bundle>, array<string, bool>> $bundles */ |
|
94
|
|
|
$bundles = require $this->getProjectDir() . '/config/bundles.php'; |
|
95
|
|
|
$instanciatedBundleNames = []; |
|
96
|
|
|
|
|
97
|
|
|
foreach ($bundles as $class => $envs) { |
|
98
|
|
|
if (isset($envs['all']) || isset($envs[$this->environment])) { |
|
99
|
|
|
$bundle = new $class(); |
|
100
|
|
|
$instanciatedBundleNames[] = $bundle->getName(); |
|
101
|
|
|
|
|
102
|
|
|
yield $bundle; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
yield from $this->pluginLoader->getBundles($this->getKernelParameters(), $instanciatedBundleNames); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getProjectDir(): string |
|
110
|
|
|
{ |
|
111
|
|
|
if ($this->projectDir === null) { |
|
112
|
|
|
if ($dir = $_ENV['PROJECT_ROOT'] ?? $_SERVER['PROJECT_ROOT'] ?? false) { |
|
113
|
|
|
return $this->projectDir = $dir; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$r = new \ReflectionObject($this); |
|
117
|
|
|
|
|
118
|
|
|
$dir = (string) $r->getFileName(); |
|
119
|
|
|
if (!file_exists($dir)) { |
|
120
|
|
|
throw new \LogicException(sprintf('Cannot auto-detect project dir for kernel of class "%s".', $r->name)); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$dir = $rootDir = \dirname($dir); |
|
124
|
|
|
while (!file_exists($dir . '/vendor')) { |
|
125
|
|
|
if ($dir === \dirname($dir)) { |
|
126
|
|
|
return $this->projectDir = $rootDir; |
|
127
|
|
|
} |
|
128
|
|
|
$dir = \dirname($dir); |
|
129
|
|
|
} |
|
130
|
|
|
$this->projectDir = $dir; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $this->projectDir; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function boot(): void |
|
137
|
|
|
{ |
|
138
|
|
|
if ($this->booted === true) { |
|
139
|
|
|
if ($this->debug) { |
|
140
|
|
|
$this->startTime = microtime(true); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
return; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
if ($this->debug) { |
|
147
|
|
|
$this->startTime = microtime(true); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if ($this->debug && !EnvironmentHelper::hasVariable('SHELL_VERBOSITY')) { |
|
151
|
|
|
putenv('SHELL_VERBOSITY=3'); |
|
152
|
|
|
$_ENV['SHELL_VERBOSITY'] = 3; |
|
153
|
|
|
$_SERVER['SHELL_VERBOSITY'] = 3; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
try { |
|
157
|
|
|
$this->pluginLoader->initializePlugins($this->getProjectDir()); |
|
158
|
|
|
} catch (\Throwable $e) { |
|
159
|
|
|
if (\defined('\STDERR')) { |
|
160
|
|
|
fwrite(\STDERR, 'Warning: Failed to load plugins. Message: ' . $e->getMessage() . \PHP_EOL); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
// init bundles |
|
165
|
|
|
$this->initializeBundles(); |
|
166
|
|
|
|
|
167
|
|
|
// init container |
|
168
|
|
|
$this->initializeContainer(); |
|
169
|
|
|
|
|
170
|
|
|
// Taken from \Symfony\Component\HttpKernel\Kernel::preBoot() |
|
171
|
|
|
/** @var ContainerInterface $container */ |
|
172
|
|
|
$container = $this->container; |
|
173
|
|
|
|
|
174
|
|
|
if ($container->hasParameter('kernel.trusted_hosts') && $trustedHosts = $container->getParameter('kernel.trusted_hosts')) { |
|
175
|
|
|
Request::setTrustedHosts($trustedHosts); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
if ($container->hasParameter('kernel.trusted_proxies') && $container->hasParameter('kernel.trusted_headers') && $trustedProxies = $container->getParameter('kernel.trusted_proxies')) { |
|
179
|
|
|
\assert(\is_string($trustedProxies) || \is_array($trustedProxies)); |
|
180
|
|
|
$trustedHeaderSet = $container->getParameter('kernel.trusted_headers'); |
|
181
|
|
|
\assert(\is_int($trustedHeaderSet)); |
|
182
|
|
|
Request::setTrustedProxies(\is_array($trustedProxies) ? $trustedProxies : array_map('trim', explode(',', $trustedProxies)), $trustedHeaderSet); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
foreach ($this->getBundles() as $bundle) { |
|
186
|
|
|
$bundle->setContainer($this->container); |
|
187
|
|
|
$bundle->boot(); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
$this->initializeDatabaseConnectionVariables(); |
|
191
|
|
|
|
|
192
|
|
|
$this->booted = true; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public static function getConnection(): Connection |
|
196
|
|
|
{ |
|
197
|
|
|
if (self::$connection) { |
|
198
|
|
|
return self::$connection; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
self::$connection = MySQLFactory::create(); |
|
202
|
|
|
|
|
203
|
|
|
return self::$connection; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
public function getCacheDir(): string |
|
207
|
|
|
{ |
|
208
|
|
|
return sprintf( |
|
209
|
|
|
'%s/var/cache/%s_h%s%s', |
|
210
|
|
|
$this->getProjectDir(), |
|
211
|
|
|
$this->getEnvironment(), |
|
212
|
|
|
$this->getCacheHash(), |
|
213
|
|
|
EnvironmentHelper::getVariable('TEST_TOKEN') ?? '' |
|
214
|
|
|
); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
public function getPluginLoader(): KernelPluginLoader |
|
218
|
|
|
{ |
|
219
|
|
|
return $this->pluginLoader; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
public function shutdown(): void |
|
223
|
|
|
{ |
|
224
|
|
|
if (!$this->booted) { |
|
225
|
|
|
return; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
// keep connection when rebooting |
|
229
|
|
|
if (!$this->rebooting) { |
|
230
|
|
|
self::$connection = null; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
parent::shutdown(); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
public function reboot(?string $warmupDir, ?KernelPluginLoader $pluginLoader = null, ?string $cacheId = null): void |
|
237
|
|
|
{ |
|
238
|
|
|
$this->rebooting = true; |
|
239
|
|
|
|
|
240
|
|
|
try { |
|
241
|
|
|
if ($pluginLoader) { |
|
242
|
|
|
$this->pluginLoader = $pluginLoader; |
|
243
|
|
|
} |
|
244
|
|
|
if ($cacheId) { |
|
245
|
|
|
$this->cacheId = $cacheId; |
|
246
|
|
|
} |
|
247
|
|
|
parent::reboot($warmupDir); |
|
248
|
|
|
} finally { |
|
249
|
|
|
$this->rebooting = false; |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void |
|
254
|
|
|
{ |
|
255
|
|
|
$container->setParameter('.container.dumper.inline_class_loader', true); |
|
256
|
|
|
$container->setParameter('.container.dumper.inline_factories', true); |
|
257
|
|
|
|
|
258
|
|
|
$confDir = $this->getProjectDir() . '/config'; |
|
259
|
|
|
|
|
260
|
|
|
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); |
|
261
|
|
|
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); |
|
262
|
|
|
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); |
|
263
|
|
|
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
protected function configureRoutes(RoutingConfigurator $routes): void |
|
267
|
|
|
{ |
|
268
|
|
|
$confDir = $this->getProjectDir() . '/config'; |
|
269
|
|
|
|
|
270
|
|
|
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, 'glob'); |
|
271
|
|
|
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); |
|
272
|
|
|
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, 'glob'); |
|
273
|
|
|
|
|
274
|
|
|
$this->addBundleRoutes($routes); |
|
275
|
|
|
$this->addApiRoutes($routes); |
|
276
|
|
|
$this->addBundleOverwrites($routes); |
|
277
|
|
|
$this->addFallbackRoute($routes); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* {@inheritdoc} |
|
282
|
|
|
* |
|
283
|
|
|
* @return array<string, mixed> |
|
284
|
|
|
*/ |
|
285
|
|
|
protected function getKernelParameters(): array |
|
286
|
|
|
{ |
|
287
|
|
|
$parameters = parent::getKernelParameters(); |
|
288
|
|
|
|
|
289
|
|
|
$activePluginMeta = []; |
|
290
|
|
|
|
|
291
|
|
|
foreach ($this->pluginLoader->getPluginInstances()->getActives() as $plugin) { |
|
292
|
|
|
$class = $plugin::class; |
|
293
|
|
|
$activePluginMeta[$class] = [ |
|
294
|
|
|
'name' => $plugin->getName(), |
|
295
|
|
|
'path' => $plugin->getPath(), |
|
296
|
|
|
'class' => $class, |
|
297
|
|
|
]; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
$pluginDir = $this->pluginLoader->getPluginDir($this->getProjectDir()); |
|
301
|
|
|
|
|
302
|
|
|
$coreDir = \dirname((string) (new \ReflectionClass(self::class))->getFileName()); |
|
303
|
|
|
|
|
304
|
|
|
return array_merge( |
|
305
|
|
|
$parameters, |
|
306
|
|
|
[ |
|
307
|
|
|
'kernel.cache.hash' => $this->getCacheHash(), |
|
308
|
|
|
'kernel.shopware_version' => $this->shopwareVersion, |
|
309
|
|
|
'kernel.shopware_version_revision' => $this->shopwareVersionRevision, |
|
310
|
|
|
'kernel.shopware_core_dir' => $coreDir, |
|
311
|
|
|
'kernel.plugin_dir' => $pluginDir, |
|
312
|
|
|
'kernel.app_dir' => rtrim($this->getProjectDir(), '/') . '/custom/apps', |
|
313
|
|
|
'kernel.active_plugins' => $activePluginMeta, |
|
314
|
|
|
'kernel.plugin_infos' => $this->pluginLoader->getPluginInfos(), |
|
315
|
|
|
'kernel.supported_api_versions' => [2, 3, 4], |
|
316
|
|
|
'defaults_bool_true' => true, |
|
317
|
|
|
'defaults_bool_false' => false, |
|
318
|
|
|
'default_whitespace' => ' ', |
|
319
|
|
|
] |
|
320
|
|
|
); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
protected function getCacheHash(): string |
|
324
|
|
|
{ |
|
325
|
|
|
$plugins = []; |
|
326
|
|
|
foreach ($this->pluginLoader->getPluginInfos() as $plugin) { |
|
327
|
|
|
if ($plugin['active'] === false) { |
|
328
|
|
|
continue; |
|
329
|
|
|
} |
|
330
|
|
|
$plugins[$plugin['name']] = $plugin['version']; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
$pluginHash = md5((string) json_encode($plugins, \JSON_THROW_ON_ERROR)); |
|
334
|
|
|
|
|
335
|
|
|
return md5((string) \json_encode([ |
|
336
|
|
|
$this->cacheId, |
|
337
|
|
|
substr((string) $this->shopwareVersionRevision, 0, 8), |
|
338
|
|
|
substr($pluginHash, 0, 8), |
|
339
|
|
|
EnvironmentHelper::getVariable('DATABASE_URL', ''), |
|
340
|
|
|
], \JSON_THROW_ON_ERROR)); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
protected function initializeDatabaseConnectionVariables(): void |
|
344
|
|
|
{ |
|
345
|
|
|
$shopwareSkipConnectionVariables = EnvironmentHelper::getVariable('SHOPWARE_SKIP_CONNECTION_VARIABLES', false); |
|
346
|
|
|
|
|
347
|
|
|
if ($shopwareSkipConnectionVariables) { |
|
348
|
|
|
return; |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
$connection = self::getConnection(); |
|
352
|
|
|
|
|
353
|
|
|
try { |
|
354
|
|
|
$setSessionVariables = (bool) EnvironmentHelper::getVariable('SQL_SET_DEFAULT_SESSION_VARIABLES', true); |
|
355
|
|
|
$connectionVariables = []; |
|
356
|
|
|
|
|
357
|
|
|
$timeZoneSupportEnabled = (bool) EnvironmentHelper::getVariable('SHOPWARE_DBAL_TIMEZONE_SUPPORT_ENABLED', false); |
|
358
|
|
|
if ($timeZoneSupportEnabled) { |
|
359
|
|
|
$connectionVariables[] = 'SET @@session.time_zone = "UTC"'; |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
if ($setSessionVariables) { |
|
363
|
|
|
$connectionVariables[] = 'SET @@group_concat_max_len = CAST(IF(@@group_concat_max_len > 320000, @@group_concat_max_len, 320000) AS UNSIGNED)'; |
|
364
|
|
|
$connectionVariables[] = 'SET sql_mode=(SELECT REPLACE(@@sql_mode,\'ONLY_FULL_GROUP_BY\',\'\'))'; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
if (empty($connectionVariables)) { |
|
368
|
|
|
return; |
|
369
|
|
|
} |
|
370
|
|
|
$connection->executeQuery(implode(';', $connectionVariables)); |
|
371
|
|
|
} catch (\Throwable) { |
|
|
|
|
|
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* Dumps the preload file to an always known location outside the generated cache folder name |
|
377
|
|
|
*/ |
|
378
|
|
|
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, string $class, string $baseClass): void |
|
379
|
|
|
{ |
|
380
|
|
|
parent::dumpContainer($cache, $container, $class, $baseClass); |
|
381
|
|
|
$cacheDir = $this->getCacheDir(); |
|
382
|
|
|
$cacheName = basename($cacheDir); |
|
383
|
|
|
$fileName = substr(basename($cache->getPath()), 0, -3) . 'preload.php'; |
|
384
|
|
|
|
|
385
|
|
|
$preloadFile = \dirname($cacheDir) . '/opcache-preload.php'; |
|
386
|
|
|
|
|
387
|
|
|
$loader = <<<PHP |
|
388
|
|
|
<?php |
|
389
|
|
|
|
|
390
|
|
|
require_once __DIR__ . '/#CACHE_PATH#'; |
|
391
|
|
|
PHP; |
|
392
|
|
|
|
|
393
|
|
|
file_put_contents($preloadFile, str_replace( |
|
394
|
|
|
['#CACHE_PATH#'], |
|
395
|
|
|
[$cacheName . '/' . $fileName], |
|
396
|
|
|
$loader |
|
397
|
|
|
)); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
private function addApiRoutes(RoutingConfigurator $routes): void |
|
401
|
|
|
{ |
|
402
|
|
|
$routes->import('.', 'api'); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
private function addBundleRoutes(RoutingConfigurator $routes): void |
|
406
|
|
|
{ |
|
407
|
|
|
foreach ($this->getBundles() as $bundle) { |
|
408
|
|
|
if ($bundle instanceof Framework\Bundle) { |
|
409
|
|
|
$bundle->configureRoutes($routes, $this->environment); |
|
410
|
|
|
} |
|
411
|
|
|
} |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
private function addBundleOverwrites(RoutingConfigurator $routes): void |
|
415
|
|
|
{ |
|
416
|
|
|
foreach ($this->getBundles() as $bundle) { |
|
417
|
|
|
if ($bundle instanceof Framework\Bundle) { |
|
418
|
|
|
$bundle->configureRouteOverwrites($routes, $this->environment); |
|
419
|
|
|
} |
|
420
|
|
|
} |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
private function addFallbackRoute(RoutingConfigurator $routes): void |
|
424
|
|
|
{ |
|
425
|
|
|
// detail routes |
|
426
|
|
|
$route = new Route('/'); |
|
427
|
|
|
$route->setMethods(['GET']); |
|
428
|
|
|
$route->setDefault('_controller', FallbackController::class . '::rootFallback'); |
|
429
|
|
|
$route->setDefault(PlatformRequest::ATTRIBUTE_ROUTE_SCOPE, ['storefront']); |
|
430
|
|
|
|
|
431
|
|
|
$routes->add('root.fallback', $route->getPath()); |
|
432
|
|
|
} |
|
433
|
|
|
} |
|
434
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: