Kernel.php 2.5 KB

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