|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2020 SURFnet B.V. |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace App; |
|
19
|
|
|
|
|
20
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
|
21
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
22
|
|
|
use Symfony\Component\Config\Resource\FileResource; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
24
|
|
|
use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
|
25
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
|
26
|
|
|
|
|
27
|
|
|
class Kernel extends BaseKernel |
|
28
|
|
|
{ |
|
29
|
|
|
use MicroKernelTrait; |
|
30
|
|
|
|
|
31
|
|
|
private const CONFIG_EXTS = '.{php,xml,yaml}'; |
|
32
|
|
|
|
|
33
|
|
|
public function registerBundles(): iterable |
|
34
|
|
|
{ |
|
35
|
|
|
$contents = require $this->getProjectDir().'/config/bundles.php'; |
|
36
|
|
|
foreach ($contents as $class => $envs) { |
|
37
|
|
|
if ($envs[$this->environment] ?? $envs['all'] ?? false) { |
|
38
|
|
|
yield new $class(); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getProjectDir(): string |
|
44
|
|
|
{ |
|
45
|
|
|
return \dirname(__DIR__); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void |
|
49
|
|
|
{ |
|
50
|
|
|
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); |
|
51
|
|
|
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug); |
|
52
|
|
|
$container->setParameter('container.dumper.inline_factories', true); |
|
53
|
|
|
$confDir = $this->getProjectDir().'/config'; |
|
54
|
|
|
|
|
55
|
|
|
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob'); |
|
56
|
|
|
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob'); |
|
57
|
|
|
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob'); |
|
58
|
|
|
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes): void |
|
62
|
|
|
{ |
|
63
|
|
|
$confDir = $this->getProjectDir().'/config'; |
|
64
|
|
|
|
|
65
|
|
|
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob'); |
|
66
|
|
|
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob'); |
|
67
|
|
|
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|