Created
September 26, 2017 13:15
-
-
Save maximecolin/be4dea80a72dd8de0d0f282a95273533 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | |
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | |
use Symfony\Component\Config\Definition\ConfigurationInterface; | |
use Symfony\Component\Config\Loader\LoaderInterface; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface; | |
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; | |
use Symfony\Component\HttpKernel\Kernel as BaseKernel; | |
use Symfony\Component\Routing\RouteCollectionBuilder; | |
class Kernel extends BaseKernel implements ExtensionInterface, ConfigurationExtensionInterface | |
{ | |
use MicroKernelTrait; | |
private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; | |
public function getCacheDir(): string | |
{ | |
return dirname(__DIR__).'/var/cache/'.$this->environment; | |
} | |
public function getLogDir(): string | |
{ | |
return dirname(__DIR__).'/var/log'; | |
} | |
public function registerBundles(): iterable | |
{ | |
$contents = require dirname(__DIR__).'/config/bundles.php'; | |
foreach ($contents as $class => $envs) { | |
if (isset($envs['all']) || isset($envs[$this->environment])) { | |
yield new $class(); | |
} | |
} | |
} | |
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void | |
{ | |
$confDir = dirname(__DIR__).'/config'; | |
$loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob'); | |
if (is_dir($confDir.'/packages/'.$this->environment)) { | |
$loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob'); | |
} | |
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob'); | |
$loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob'); | |
$container->setParameter('foobar', 123); | |
} | |
protected function configureRoutes(RouteCollectionBuilder $routes): void | |
{ | |
$confDir = dirname(__DIR__).'/config'; | |
if (is_dir($confDir.'/routes/')) { | |
$routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob'); | |
} | |
if (is_dir($confDir.'/routes/'.$this->environment)) { | |
$routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob'); | |
} | |
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob'); | |
} | |
protected function build(ContainerBuilder $container) | |
{ | |
$container->registerExtension($this); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getConfiguration(array $config, ContainerBuilder $container) | |
{ | |
return new class implements ConfigurationInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getConfigTreeBuilder() | |
{ | |
$treeBuilder = new TreeBuilder(); | |
$rootNode = $treeBuilder->root('app'); | |
$rootNode | |
->children() | |
->scalarNode('foobar') | |
->isRequired() | |
->end(); | |
return $treeBuilder; | |
} | |
}; | |
} | |
/** | |
* Loads a specific configuration. | |
* | |
* @param array $configs An array of configuration values | |
* @param ContainerBuilder $container A ContainerBuilder instance | |
* | |
* @throws \InvalidArgumentException When provided tag is not defined in this extension | |
*/ | |
public function load(array $configs, ContainerBuilder $container) | |
{ | |
var_dump('dsf'); | |
} | |
/** | |
* Returns the namespace to be used for this extension (XML namespace). | |
* | |
* @return string The XML namespace | |
*/ | |
public function getNamespace() | |
{ | |
return ''; | |
} | |
/** | |
* Returns the base path for the XSD files. | |
* | |
* @return string The XSD base path | |
*/ | |
public function getXsdValidationBasePath() | |
{ | |
return ''; | |
} | |
/** | |
* Returns the recommended alias to use in XML. | |
* | |
* This alias is also the mandatory prefix to use when using YAML. | |
* | |
* @return string The alias | |
*/ | |
public function getAlias() | |
{ | |
return 'app'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment