| 1 | <?php |
||
| 2 | /* |
||
| 3 | * This file is part of the Symfony package. |
||
| 4 | * |
||
| 5 | * (c) Fabien Potencier <[email protected]> |
||
| 6 | * |
||
| 7 | * For the full copyright and license information, please view the LICENSE |
||
| 8 | * file that was distributed with this source code. |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace App; |
||
| 12 | |||
| 13 | use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
||
| 14 | use Symfony\Component\Config\Loader\LoaderInterface; |
||
| 15 | use Symfony\Component\Config\Resource\FileResource; |
||
| 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
| 17 | use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
||
| 18 | use Symfony\Component\Routing\RouteCollectionBuilder; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * The Kernel is the heart of the Symfony system. |
||
| 22 | * |
||
| 23 | * It manages an environment made of bundles. |
||
| 24 | * |
||
| 25 | * @author Fabien Potencier <[email protected]> |
||
| 26 | */ |
||
| 27 | class Kernel extends BaseKernel |
||
| 28 | { |
||
| 29 | use MicroKernelTrait; |
||
| 30 | |||
| 31 | const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Gets the cache directory. |
||
| 35 | * |
||
| 36 | * @return string The cache directory |
||
| 37 | */ |
||
| 38 | public function getCacheDir() |
||
| 39 | { |
||
| 40 | return $this->getProjectDir().'/var/cache/'.$this->environment; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Gets the log directory. |
||
| 45 | * |
||
| 46 | * @return string The log directory |
||
| 47 | */ |
||
| 48 | public function getLogDir() |
||
| 49 | { |
||
| 50 | return $this->getProjectDir().'/var/log'; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Returns an array of bundles to register. |
||
| 55 | * |
||
| 56 | * @return iterable|BundleInterface[] An iterable of bundle instances |
||
| 57 | */ |
||
| 58 | public function registerBundles() |
||
| 59 | { |
||
| 60 | $contents = require $this->getProjectDir().'/config/bundles.php'; |
||
| 61 | foreach ($contents as $class => $envs) { |
||
| 62 | if (isset($envs['all']) || isset($envs[$this->environment])) { |
||
| 63 | yield new $class(); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Configures the container. |
||
| 70 | * |
||
| 71 | * You can register extensions: |
||
| 72 | * |
||
| 73 | * $c->loadFromExtension('framework', array( |
||
| 74 | * 'secret' => '%secret%' |
||
| 75 | * )); |
||
| 76 | * |
||
| 77 | * Or services: |
||
| 78 | * |
||
| 79 | * $c->register('halloween', 'FooBundle\HalloweenProvider'); |
||
| 80 | * |
||
| 81 | * Or parameters: |
||
| 82 | * |
||
| 83 | * $c->setParameter('halloween', 'lot of fun'); |
||
| 84 | * |
||
| 85 | * @param ContainerBuilder $container |
||
| 86 | * @param LoaderInterface $loader |
||
| 87 | */ |
||
| 88 | protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) |
||
| 89 | { |
||
| 90 | $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); |
||
| 91 | // Feel free to remove the "container.autowiring.strict_mode" parameter |
||
| 92 | // if you are using symfony/dependency-injection 4.0+ as it's the default behavior |
||
| 93 | $container->setParameter('container.autowiring.strict_mode', true); |
||
| 94 | $container->setParameter('container.dumper.inline_class_loader', true); |
||
| 95 | $confDir = $this->getProjectDir().'/config'; |
||
| 96 | |||
| 97 | $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob'); |
||
| 98 | $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); |
||
| 99 | $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob'); |
||
| 100 | $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob'); |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Add or import routes into your application. |
||
| 105 | * |
||
| 106 | * $routes->import('config/routing.yml'); |
||
| 107 | * $routes->add('/admin', 'AppBundle:Admin:dashboard', 'admin_dashboard'); |
||
| 108 | * |
||
| 109 | * @param RouteCollectionBuilder $routes |
||
| 110 | */ |
||
| 111 | protected function configureRoutes(RouteCollectionBuilder $routes) |
||
| 112 | { |
||
| 113 | $confDir = $this->getProjectDir().'/config'; |
||
| 114 | |||
| 115 | $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob'); |
||
| 116 | $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
||
| 117 | $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob'); |
||
| 118 | } |
||
| 119 | } |
||
| 120 |