1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Symfony package. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
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 App; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
15
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
18
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
19
|
|
|
|
20
|
|
|
class Kernel extends BaseKernel |
21
|
|
|
{ |
22
|
|
|
use MicroKernelTrait; |
23
|
|
|
|
24
|
|
|
const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
25
|
|
|
|
26
|
|
|
public function getCacheDir() |
27
|
|
|
{ |
28
|
|
|
return $this->getProjectDir().'/var/cache/'.$this->environment; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getLogDir() |
32
|
|
|
{ |
33
|
|
|
return $this->getProjectDir().'/var/log'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function registerBundles() |
37
|
|
|
{ |
38
|
|
|
$contents = require $this->getProjectDir().'/config/bundles.php'; |
39
|
|
|
foreach ($contents as $class => $envs) { |
40
|
|
|
if (isset($envs['all']) || isset($envs[$this->environment])) { |
41
|
|
|
yield new $class(); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) |
47
|
|
|
{ |
48
|
|
|
$container->setParameter('container.dumper.inline_class_loader', true); |
49
|
|
|
$confDir = $this->getProjectDir().'/config'; |
50
|
|
|
$loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob'); |
51
|
|
View Code Duplication |
if (is_dir($confDir.'/packages/'.$this->environment)) { |
|
|
|
|
52
|
|
|
$loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); |
53
|
|
|
} |
54
|
|
|
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob'); |
55
|
|
|
$loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes) |
59
|
|
|
{ |
60
|
|
|
$confDir = $this->getProjectDir().'/config'; |
61
|
|
|
if (is_dir($confDir.'/routes/')) { |
62
|
|
|
$routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob'); |
63
|
|
|
} |
64
|
|
View Code Duplication |
if (is_dir($confDir.'/routes/'.$this->environment)) { |
|
|
|
|
65
|
|
|
$routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
66
|
|
|
} |
67
|
|
|
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.