src/Kernel.php line 45

Open in your IDE?
  1. <?php
  2. namespace App;
  3. use App\Tus\DependencyInjection\Compiler\TusFileCollectorPass;
  4. use App\Tus\FileCollectorInterface;
  5. use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableInterface;
  6. use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeAwareInterface;
  7. use Roothirsch\CoreBundle\Behaviors\Attributable\Debug\AttributeDumpCaster;
  8. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  9. use Symfony\Component\Config\Loader\LoaderInterface;
  10. use Symfony\Component\DependencyInjection\ContainerBuilder;
  11. use Symfony\Component\Dotenv\Dotenv;
  12. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  13. use Symfony\Component\Routing\RouteCollectionBuilder;
  14. use Symfony\Component\VarDumper\Cloner\VarCloner;
  15. class Kernel extends BaseKernel
  16. {
  17. use MicroKernelTrait;
  18. const CONFIG_EXTS = '.{php,xml,yaml,yml}';
  19. public function __construct(string $environment, bool $debug)
  20. {
  21. (new Dotenv())->load(__DIR__ . '/../.env');
  22. $this->environment = $environment;
  23. $this->debug = $debug;
  24. VarCloner::$defaultCasters[AttributableInterface::class] = [AttributeDumpCaster::class, 'cast'];
  25. }
  26. public function getCacheDir()
  27. {
  28. return $this->getProjectDir() . '/var/cache/' . $this->environment;
  29. }
  30. public function getLogDir()
  31. {
  32. return $this->getProjectDir() . '/var/log';
  33. }
  34. public function registerBundles()
  35. {
  36. $contents = require $this->getProjectDir() . '/config/bundles.php';
  37. foreach ($contents as $class => $envs) {
  38. if (isset($envs['all']) || isset($envs[$this->environment])) {
  39. yield new $class();
  40. }
  41. }
  42. }
  43. protected function build(ContainerBuilder $containerBuilder): void
  44. {
  45. $containerBuilder->registerForAutoconfiguration(FileCollectorInterface::class)->addTag('app.tus.file_collector');
  46. $containerBuilder->addCompilerPass(new TusFileCollectorPass());
  47. }
  48. protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
  49. {
  50. $container->setParameter('container.autowiring.strict_mode', true);
  51. $container->setParameter('container.dumper.inline_class_loader', true);
  52. $confDir = $this->getProjectDir() . '/config';
  53. $loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob');
  54. $loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob');
  55. $loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob');
  56. $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob');
  57. }
  58. protected function configureRoutes(RouteCollectionBuilder $routes)
  59. {
  60. $confDir = $this->getProjectDir() . '/config';
  61. $routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob');
  62. $routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob');
  63. $routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
  64. }
  65. }