Add symfony 4 configuration loading when bootstrap is null; tweaked formatting, naming, tests and readme
This commit is contained in:
15
README.md
15
README.md
@@ -62,6 +62,19 @@ FriendsOfBehat\SymfonyExtension:
|
||||
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.
|
||||
|
||||
@@ -8,9 +8,12 @@ Feature: Not crashing Behat
|
||||
"""
|
||||
default:
|
||||
extensions:
|
||||
FriendsOfBehat\SymfonyExtension:
|
||||
kernel:
|
||||
bootstrap: ~
|
||||
FriendsOfBehat\SymfonyExtension: ~
|
||||
"""
|
||||
And a file "app/autoload.php" containing:
|
||||
"""
|
||||
<?php
|
||||
|
||||
"""
|
||||
And a file "app/AppKernel.php" containing:
|
||||
"""
|
||||
@@ -36,11 +39,16 @@ Feature: Not crashing Behat
|
||||
extensions:
|
||||
FriendsOfBehat\SymfonyExtension:
|
||||
kernel:
|
||||
bootstrap: ~
|
||||
bootstrap: app/autoload.php
|
||||
path: app/MyKernel.php
|
||||
class: MyKernel
|
||||
env: test
|
||||
debug: true
|
||||
"""
|
||||
And a file "app/autoload.php" containing:
|
||||
"""
|
||||
<?php
|
||||
|
||||
"""
|
||||
And a file "app/MyKernel.php" containing:
|
||||
"""
|
||||
@@ -163,11 +171,13 @@ Feature: Not crashing Behat
|
||||
"""
|
||||
default:
|
||||
extensions:
|
||||
FriendsOfBehat\SymfonyExtension:
|
||||
kernel:
|
||||
bootstrap: ~
|
||||
|
||||
FriendsOfBehat\SymfonyExtension: ~
|
||||
FriendsOfBehat\CrossContainerExtension: ~
|
||||
"""
|
||||
And a file "app/autoload.php" containing:
|
||||
"""
|
||||
<?php
|
||||
|
||||
"""
|
||||
And a file "app/AppKernel.php" containing:
|
||||
"""
|
||||
|
||||
@@ -122,8 +122,9 @@ final class SymfonyExtension implements Extension
|
||||
->children()
|
||||
->scalarNode('env_file')->end()
|
||||
->arrayNode('kernel')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('bootstrap')->end()
|
||||
->scalarNode('bootstrap')->defaultFalse()->end()
|
||||
->scalarNode('path')->end()
|
||||
->scalarNode('class')->end()
|
||||
->scalarNode('env')->end()
|
||||
@@ -165,15 +166,17 @@ final class SymfonyExtension implements Extension
|
||||
* @param array $userConfig
|
||||
* @return array
|
||||
*/
|
||||
private function autoconfigure(ContainerBuilder $container, array $userConfig) {
|
||||
|
||||
private function autoconfigure(ContainerBuilder $container, array $userConfig): array
|
||||
{
|
||||
$defaults = self::SYMFONY_DEFAULTS;
|
||||
|
||||
$symfony4KernelPath = sprintf('%s/%s', $container->getParameter('paths.base'), self::SYMFONY_4_DEFAULTS['kernel']['path']);
|
||||
if (file_exists($symfony4KernelPath)) {
|
||||
$symfonyFourKernelPath = sprintf('%s/%s', $container->getParameter('paths.base'), self::SYMFONY_4_DEFAULTS['kernel']['path']);
|
||||
if ($userConfig['kernel']['bootstrap'] === null || file_exists($symfonyFourKernelPath)) {
|
||||
$defaults = self::SYMFONY_4_DEFAULTS;
|
||||
}
|
||||
|
||||
$userConfig['kernel']['bootstrap'] = $userConfig['kernel']['bootstrap'] === false ? null : $userConfig['kernel']['bootstrap'];
|
||||
|
||||
$config = array_replace_recursive($defaults, $userConfig);
|
||||
|
||||
if (null !== $config['env_file']) {
|
||||
|
||||
Reference in New Issue
Block a user