Changeset View
Changeset View
Standalone View
Standalone View
src/Kernel.php
- This file was added.
1 | <?php | ||||
---|---|---|---|---|---|
2 | | ||||
3 | namespace App; | ||||
4 | | ||||
5 | use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | ||||
6 | use Symfony\Component\Config\Loader\LoaderInterface; | ||||
7 | use Symfony\Component\Config\Resource\FileResource; | ||||
8 | use Symfony\Component\DependencyInjection\ContainerBuilder; | ||||
9 | use Symfony\Component\HttpKernel\Kernel as BaseKernel; | ||||
10 | use Symfony\Component\Routing\RouteCollectionBuilder; | ||||
11 | | ||||
12 | class Kernel extends BaseKernel | ||||
13 | { | ||||
14 | use MicroKernelTrait; | ||||
15 | | ||||
16 | const CONFIG_EXTS = '.{php,xml,yaml,yml}'; | ||||
17 | | ||||
18 | public function getCacheDir() | ||||
19 | { | ||||
20 | return $this->getProjectDir().'/var/cache/'.$this->environment; | ||||
21 | } | ||||
22 | | ||||
23 | public function getLogDir() | ||||
24 | { | ||||
25 | return $this->getProjectDir().'/var/log'; | ||||
26 | } | ||||
27 | | ||||
28 | public function registerBundles() | ||||
29 | { | ||||
30 | $contents = require $this->getProjectDir().'/config/bundles.php'; | ||||
31 | foreach ($contents as $class => $envs) { | ||||
32 | if ($envs[$this->environment] ?? $envs['all'] ?? false) { | ||||
33 | yield new $class(); | ||||
34 | } | ||||
35 | } | ||||
36 | } | ||||
37 | | ||||
38 | protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) | ||||
39 | { | ||||
40 | $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); | ||||
41 | $container->setParameter('container.dumper.inline_class_loader', true); | ||||
42 | $confDir = $this->getProjectDir().'/config'; | ||||
43 | | ||||
44 | $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob'); | ||||
45 | $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); | ||||
46 | $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob'); | ||||
47 | $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob'); | ||||
48 | } | ||||
49 | | ||||
50 | protected function configureRoutes(RouteCollectionBuilder $routes) | ||||
51 | { | ||||
52 | $confDir = $this->getProjectDir().'/config'; | ||||
53 | | ||||
54 | $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob'); | ||||
55 | $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); | ||||
56 | $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob'); | ||||
57 | } | ||||
58 | } |