Kernel.php 2.1 KB

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