Symfony4 support
This commit is contained in:
@@ -27,6 +27,7 @@ use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
final class SymfonyExtension implements Extension
|
||||
{
|
||||
@@ -90,6 +91,7 @@ final class SymfonyExtension implements Extension
|
||||
$builder
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('env_file')->defaultNull()->end()
|
||||
->arrayNode('kernel')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
@@ -110,6 +112,15 @@ final class SymfonyExtension implements Extension
|
||||
*/
|
||||
public function load(ContainerBuilder $container, array $config): void
|
||||
{
|
||||
if (null !== $config['env_file']) {
|
||||
$this->loadEnvVars($container, $config['env_file']);
|
||||
|
||||
$environment = getenv('APP_ENV');
|
||||
$config['kernel']['env'] = $environment ?? 'test';
|
||||
} else {
|
||||
$this->requireKernelBootstrapFile($container->getParameter('paths.base'), $config['bootstrap']);
|
||||
}
|
||||
|
||||
$this->loadKernel($container, $config['kernel']);
|
||||
$this->loadKernelContainer($container);
|
||||
|
||||
@@ -129,6 +140,16 @@ final class SymfonyExtension implements Extension
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $fileName
|
||||
*/
|
||||
private function loadEnvVars(ContainerBuilder $container, string $fileName): void
|
||||
{
|
||||
$envFilePath = sprintf('%s/%s', $container->getParameter('paths.base'), $fileName);
|
||||
(new Dotenv())->load($envFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
@@ -142,8 +163,6 @@ final class SymfonyExtension implements Extension
|
||||
$definition->setFile($this->getKernelFile($container->getParameter('paths.base'), $config['path']));
|
||||
|
||||
$container->setDefinition(self::KERNEL_ID, $definition);
|
||||
|
||||
$this->requireKernelBootstrapFile($container->getParameter('paths.base'), $config['bootstrap']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,6 +222,8 @@ final class SymfonyExtension implements Extension
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function declareSymfonyContainers(ContainerBuilder $container): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user