Set up kernel file & bootstrap application if needed

This commit is contained in:
Kamil Kokot
2016-11-03 12:54:54 +01:00
parent 8437a3b18a
commit f98a7a1d94

View File

@@ -123,9 +123,11 @@ final class SymfonyExtension implements Extension
$config['debug'], $config['debug'],
)); ));
$definition->addMethodCall('boot'); $definition->addMethodCall('boot');
$definition->setFile($this->getKernelFile($container->getParameter('paths.base'), $config['path']));
$container->setDefinition(self::KERNEL_ID, $definition); $container->setDefinition(self::KERNEL_ID, $definition);
$container->setParameter(self::KERNEL_ID . '.path', $config['path']);
$container->setParameter(self::KERNEL_ID . '.bootstrap', $config['bootstrap']); $this->requireKernelBootstrapFile($container->getParameter('paths.base'), $config['bootstrap']);
} }
/** /**
@@ -199,4 +201,54 @@ final class SymfonyExtension implements Extension
new Reference(self::DRIVER_KERNEL_ID) new Reference(self::DRIVER_KERNEL_ID)
)); ));
} }
/**
* @param string $basePath
* @param string $kernelPath
*
* @return string|null
*/
private function getKernelFile($basePath, $kernelPath)
{
$possibleFiles = [
sprintf('%s/%s', $basePath, $kernelPath),
$kernelPath,
];
foreach ($possibleFiles as $possibleFile) {
if (file_exists($possibleFile)) {
return $possibleFile;
}
}
return null;
}
/**
* @param string $basePath
* @param string|null $bootstrapPath
*
* @throws \DomainException
*/
private function requireKernelBootstrapFile($basePath, $bootstrapPath)
{
if (null === $bootstrapPath) {
return;
}
$possiblePaths = [
sprintf('%s/%s', $basePath, $bootstrapPath),
$bootstrapPath,
];
foreach ($possiblePaths as $possiblePath) {
if (file_exists($possiblePath)) {
require_once $possiblePath;
return;
}
}
throw new \DomainException('Could not load bootstrap file.');
}
} }