Add symfony 4 configuration loading when bootstrap is null; tweaked formatting, naming, tests and readme

This commit is contained in:
Adrian Zmenda
2018-08-10 17:56:50 +02:00
parent 141074a24e
commit 149d41087f
3 changed files with 40 additions and 14 deletions

View File

@@ -62,6 +62,19 @@ FriendsOfBehat\SymfonyExtension:
debug: true # When explicitly set, will override APP_DEBUG loaded from env_file file debug: true # When explicitly set, will override APP_DEBUG loaded from env_file file
``` ```
Symfony 4 is detected, based on the existence of `src/Kernel.php` file, so if you did not migrate to new Symfony structure yet; you need to set those values yourself. Symfony 4 is automatically detected, based on the existence of default `src/Kernel.php` kernel file.
If you did not migrate to new Symfony structure yet or you are using custom paths/naming; you need to configure `kernel.boostrap` parameter, to enable default Symfony 4 configuration as shown in the example below:
```
FriendsOfBehat\SymfonyExtension:
# env_file: .env # loaded from the default configuration
kernel:
bootstrap: ~ # this enables default Symfony 4 configuration
path: app/AppKernel.php
# class: 'App\Kernel' # loaded from the default configuration
# env: test # loaded from the default configuration
# debug: true # loaded from the default configuration
```
Of course, you can always change each of those settings. Of course, you can always change each of those settings.

View File

@@ -8,9 +8,12 @@ Feature: Not crashing Behat
""" """
default: default:
extensions: extensions:
FriendsOfBehat\SymfonyExtension: FriendsOfBehat\SymfonyExtension: ~
kernel: """
bootstrap: ~ And a file "app/autoload.php" containing:
"""
<?php
""" """
And a file "app/AppKernel.php" containing: And a file "app/AppKernel.php" containing:
""" """
@@ -36,11 +39,16 @@ Feature: Not crashing Behat
extensions: extensions:
FriendsOfBehat\SymfonyExtension: FriendsOfBehat\SymfonyExtension:
kernel: kernel:
bootstrap: ~ bootstrap: app/autoload.php
path: app/MyKernel.php path: app/MyKernel.php
class: MyKernel class: MyKernel
env: test env: test
debug: true debug: true
"""
And a file "app/autoload.php" containing:
"""
<?php
""" """
And a file "app/MyKernel.php" containing: And a file "app/MyKernel.php" containing:
""" """
@@ -163,11 +171,13 @@ Feature: Not crashing Behat
""" """
default: default:
extensions: extensions:
FriendsOfBehat\SymfonyExtension: FriendsOfBehat\SymfonyExtension: ~
kernel:
bootstrap: ~
FriendsOfBehat\CrossContainerExtension: ~ FriendsOfBehat\CrossContainerExtension: ~
"""
And a file "app/autoload.php" containing:
"""
<?php
""" """
And a file "app/AppKernel.php" containing: And a file "app/AppKernel.php" containing:
""" """

View File

@@ -122,8 +122,9 @@ final class SymfonyExtension implements Extension
->children() ->children()
->scalarNode('env_file')->end() ->scalarNode('env_file')->end()
->arrayNode('kernel') ->arrayNode('kernel')
->addDefaultsIfNotSet()
->children() ->children()
->scalarNode('bootstrap')->end() ->scalarNode('bootstrap')->defaultFalse()->end()
->scalarNode('path')->end() ->scalarNode('path')->end()
->scalarNode('class')->end() ->scalarNode('class')->end()
->scalarNode('env')->end() ->scalarNode('env')->end()
@@ -165,15 +166,17 @@ final class SymfonyExtension implements Extension
* @param array $userConfig * @param array $userConfig
* @return array * @return array
*/ */
private function autoconfigure(ContainerBuilder $container, array $userConfig) { private function autoconfigure(ContainerBuilder $container, array $userConfig): array
{
$defaults = self::SYMFONY_DEFAULTS; $defaults = self::SYMFONY_DEFAULTS;
$symfony4KernelPath = sprintf('%s/%s', $container->getParameter('paths.base'), self::SYMFONY_4_DEFAULTS['kernel']['path']); $symfonyFourKernelPath = sprintf('%s/%s', $container->getParameter('paths.base'), self::SYMFONY_4_DEFAULTS['kernel']['path']);
if (file_exists($symfony4KernelPath)) { if ($userConfig['kernel']['bootstrap'] === null || file_exists($symfonyFourKernelPath)) {
$defaults = self::SYMFONY_4_DEFAULTS; $defaults = self::SYMFONY_4_DEFAULTS;
} }
$userConfig['kernel']['bootstrap'] = $userConfig['kernel']['bootstrap'] === false ? null : $userConfig['kernel']['bootstrap'];
$config = array_replace_recursive($defaults, $userConfig); $config = array_replace_recursive($defaults, $userConfig);
if (null !== $config['env_file']) { if (null !== $config['env_file']) {