Implement bootstrap file autodiscovering

This commit is contained in:
Kamil Kokot
2019-01-11 00:24:59 +01:00
parent fa3c02720c
commit d6701d785c
3 changed files with 142 additions and 3 deletions

View File

@@ -86,7 +86,7 @@ final class SymfonyExtension implements Extension
public function process(ContainerBuilder $container): void
{
$this->processBootstrap($container->getParameter('fob_symfony.bootstrap'));
$this->processBootstrap($this->autodiscoverBootstrap($container->getParameter('fob_symfony.bootstrap')));
}
private function registerMinkDriver(ExtensionManager $extensionManager): void
@@ -193,6 +193,44 @@ final class SymfonyExtension implements Extension
return $config;
}
/**
* @param string|bool|null $bootstrap
*/
private function autodiscoverBootstrap($bootstrap): ?string
{
if (is_string($bootstrap)) {
return $bootstrap;
}
if ($bootstrap === false) {
return null;
}
$autoconfigured = 0;
if (file_exists('config/bootstrap.php')) {
$bootstrap = 'config/bootstrap.php';
++$autoconfigured;
}
if (file_exists('app/autoload.php')) {
$bootstrap = 'app/autoload.php';
++$autoconfigured;
}
if ($autoconfigured === 2) {
throw new \RuntimeException(
'Could not autodiscover the bootstrap file. ' .
'Please define it manually with "FriendsOfBehat\SymfonyExtension.bootstrap" configuration option. ' .
'Setting that option to "false" disables autodiscovering.'
);
}
return is_string($bootstrap) ? $bootstrap : null;
}
private function processBootstrap(?string $bootstrap): void
{
if ($bootstrap === null) {