add more default Kernel class names to DefaultAnalyzedSymfonyApplicationContainer [closes #468]

This commit is contained in:
Tomas Votruba 2018-05-19 21:00:03 +02:00
parent 75ea3963d3
commit bf953ab842
3 changed files with 17 additions and 8 deletions

View File

@ -58,10 +58,26 @@ final class DefaultAnalyzedSymfonyApplicationContainer implements AnalyzedApplic
private function getContainer(): Container
{
$kernelClass = $this->parameterProvider->provideParameter(Option::KERNEL_CLASS_PARAMETER);
if ($kernelClass === null) {
$kernelClass = $this->getDefaultKernelClass();
}
$this->symfonyKernelParameterGuard->ensureKernelClassIsValid($kernelClass);
/** @var string $kernelClass */
return $this->containerFactory->createFromKernelClass($kernelClass);
}
private function getDefaultKernelClass(): ?string
{
$possibleKernelClasses = ['App\Kernel', 'Kernel', 'AppKernel'];
foreach ($possibleKernelClasses as $possibleKernelClass) {
if (class_exists($possibleKernelClass)) {
return $possibleKernelClass;
}
}
return null;
}
}

View File

@ -1,7 +1,3 @@
parameters:
# default Symfony Kernel class
kernel_class: 'App\Kernel'
imports:
- { resource: '../../packages/**/src/config/*services.yml' }
- { resource: 'services.yml' }

View File

@ -13,10 +13,7 @@ final class InvalidConfigurationConstructorInjectionRectorTest extends AbstractR
public function test(): void
{
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage(
'Kernel class "App\Kernel" provided in "parameters > kernel_class" is not autoloadable.'
. ' Make sure composer.json of your application is valid and rector is loading "vendor/autoload.php" of your application.'
);
$this->expectExceptionMessage('Make sure "kernel_class" parameters is set in rector.yml in "parameters:" section');
$this->doTestFileMatchesExpectedContent(__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc');
}