src/Kernel.php line 18

Open in your IDE?
  1. <?php
  2. namespace Whater;
  3. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  4. use Symfony\Component\Config\Loader\LoaderInterface;
  5. use Symfony\Component\Config\Resource\FileResource;
  6. use Symfony\Component\DependencyInjection\ContainerBuilder;
  7. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  8. use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
  9. use Symfony\Component\Routing\RouteCollectionBuilder;
  10. class Kernel extends BaseKernel
  11. {
  12. use MicroKernelTrait;
  13. private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
  14. public function registerBundles(): iterable
  15. {
  16. $contents = require $this->getProjectDir().'/app/bundles.php';
  17. foreach ($contents as $class => $envs) {
  18. if ($envs[$this->environment] ?? $envs['all'] ?? false) {
  19. yield new $class();
  20. }
  21. }
  22. }
  23. public function getProjectDir(): string
  24. {
  25. return \dirname(__DIR__);
  26. }
  27. protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
  28. {
  29. $container->addResource(new FileResource($this->getProjectDir().'/app/bundles.php'));
  30. $container->setParameter('container.dumper.inline_class_loader', true);
  31. $confDir = $this->getProjectDir().'/app/config';
  32. $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
  33. $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
  34. $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
  35. $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
  36. }
  37. protected function configureRoutes(RoutingConfigurator $routes): void
  38. {
  39. // $confDir = $this->getProjectDir().'/app/config';
  40. // $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
  41. // $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
  42. // $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
  43. $confDir = $this->getProjectDir() . '/app/config';
  44. $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS);
  45. $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS);
  46. $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS);
  47. }
  48. }