|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Quartz\App; |
| 4 | + |
| 5 | +use Quartz\Bridge\DI\QuartzExtension; |
| 6 | +use Quartz\Bridge\DI\QuartzJobCompilerPass; |
| 7 | +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
| 8 | +use Symfony\Component\Config\Loader\LoaderInterface; |
| 9 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 10 | +use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
| 11 | +use Symfony\Component\Routing\RouteCollectionBuilder; |
| 12 | + |
| 13 | +/** |
| 14 | + * @author Fabien Potencier <[email protected]> |
| 15 | + */ |
| 16 | +final class Kernel extends BaseKernel |
| 17 | +{ |
| 18 | + use MicroKernelTrait; |
| 19 | + |
| 20 | + private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; |
| 21 | + |
| 22 | + public function getCacheDir(): string |
| 23 | + { |
| 24 | + return dirname(__DIR__).'/var/cache/'.$this->environment; |
| 25 | + } |
| 26 | + |
| 27 | + public function getLogDir(): string |
| 28 | + { |
| 29 | + return dirname(__DIR__).'/var/logs'; |
| 30 | + } |
| 31 | + |
| 32 | + public function registerBundles(): iterable |
| 33 | + { |
| 34 | + $contents = require dirname(__DIR__).'/etc/bundles.php'; |
| 35 | + foreach ($contents as $class => $envs) { |
| 36 | + if (isset($envs['all']) || isset($envs[$this->environment])) { |
| 37 | + yield new $class(); |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void |
| 43 | + { |
| 44 | + $container->registerExtension(new QuartzExtension()); |
| 45 | + $container->addCompilerPass(new QuartzJobCompilerPass()); |
| 46 | + |
| 47 | + $confDir = dirname(__DIR__).'/etc'; |
| 48 | + $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob'); |
| 49 | + if (is_dir($confDir.'/packages/'.$this->environment)) { |
| 50 | + $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); |
| 51 | + } |
| 52 | + $loader->load($confDir.'/container'.self::CONFIG_EXTS, 'glob'); |
| 53 | + } |
| 54 | + |
| 55 | + protected function configureRoutes(RouteCollectionBuilder $routes): void |
| 56 | + { |
| 57 | + $confDir = dirname(__DIR__).'/etc'; |
| 58 | + if (is_dir($confDir.'/routing/')) { |
| 59 | + $routes->import($confDir.'/routing/*'.self::CONFIG_EXTS, '/', 'glob'); |
| 60 | + } |
| 61 | + if (is_dir($confDir.'/routing/'.$this->environment)) { |
| 62 | + $routes->import($confDir.'/routing/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); |
| 63 | + } |
| 64 | + $routes->import($confDir.'/routing'.self::CONFIG_EXTS, '/', 'glob'); |
| 65 | + } |
| 66 | +} |
0 commit comments