diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php index 3cf0268203050..af1041d86e787 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php @@ -21,7 +21,7 @@ class NoTemplatingEntryTest extends TestCase { public function test() { - $kernel = new NoTemplatingEntryKernel('dev', true); + $kernel = new NoTemplatingEntryKernel('dev', true, 'app'); $kernel->boot(); $container = $kernel->getContainer(); diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 3d5fff2779a10..de085ab4534bb 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -20,7 +20,7 @@ "symfony/config": "~3.2|~4.0", "symfony/twig-bridge": "^3.4|~4.0", "symfony/http-foundation": "~2.8|~3.0|~4.0", - "symfony/http-kernel": "^3.3|~4.0", + "symfony/http-kernel": "^3.4|~4.0", "twig/twig": "~1.34|~2.4" }, "require-dev": { diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index cd4c26063d5d9..567b11cc4acfc 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -78,15 +78,23 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl /** * Constructor. * - * @param string $environment The environment - * @param bool $debug Whether to enable debugging or not + * @param string $environment The environment + * @param bool $debug Whether to enable debugging or not + * @param string|null $name The application name */ - public function __construct($environment, $debug) + public function __construct($environment, $debug, $name = null) { $this->environment = $environment; $this->debug = (bool) $debug; $this->rootDir = $this->getRootDir(); - $this->name = $this->getName(); + + if (null === $name) { + $this->name = $this->getName(); + } elseif (preg_match('~^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$~', $name)) { + $this->name = $name; + } else { + throw new \InvalidArgumentException(sprintf('"%s" is not a valid kernel name.', $name)); + } if ($this->debug) { $this->startTime = microtime(true); @@ -297,6 +305,10 @@ public function getName() if (ctype_digit($this->name[0])) { $this->name = '_'.$this->name; } + + if ('app' !== $this->name) { + @trigger_error(sprintf('Auto-discovery of the kernel name is deprecated since Symfony 3.4 and won\'t be supported in 4.0.'), E_USER_DEPRECATED); + } } return $this->name; diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php index 5fd61bbc7e7ce..80b34b38b9dbc 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php @@ -16,6 +16,11 @@ class KernelForTest extends Kernel { + public function __construct($environment, $debug, $name = 'app') + { + parent::__construct($environment, $debug, $name); + } + public function getBundleMap() { return $this->bundleMap; diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelWithoutBundles.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelWithoutBundles.php index cee1b09fb2253..20e8f4e4f404f 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelWithoutBundles.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelWithoutBundles.php @@ -17,6 +17,11 @@ class KernelWithoutBundles extends Kernel { + public function __construct($environment, $debug, $name = 'app') + { + parent::__construct($environment, $debug, $name); + } + public function registerBundles() { return array(); diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index fd7f6f09da13d..c1535b0dd9109 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -340,7 +340,7 @@ public function testGetName() { $kernel = new KernelForTest('test', true); - $this->assertEquals('Fixtures', $kernel->getName()); + $this->assertEquals('app', $kernel->getName()); } public function testOverrideGetName() @@ -771,6 +771,10 @@ public function testKernelWithoutBundles() $this->assertTrue($kernel->getContainer()->getParameter('test_executed')); } + /** + * @group legacy + * @expectedDeprecation Auto-discovery of the kernel name is deprecated since Symfony 3.4 and won't be supported in 4.0. + */ public function testKernelRootDirNameStartingWithANumber() { $dir = __DIR__.'/Fixtures/123'; @@ -816,14 +820,14 @@ public function testKernelReset() $containerClass = get_class($kernel->getContainer()); $containerFile = (new \ReflectionClass($kernel->getContainer()))->getFileName(); - unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta'); + unlink(__DIR__.'/Fixtures/cache/custom/appCustomDebugProjectContainer.php.meta'); $kernel = new CustomProjectDirKernel(); $kernel->boot(); $this->assertSame($containerClass, get_class($kernel->getContainer())); $this->assertFileExists($containerFile); - unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta'); + unlink(__DIR__.'/Fixtures/cache/custom/appCustomDebugProjectContainer.php.meta'); $kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); }); $kernel->boot(); @@ -840,6 +844,15 @@ public function testKernelPass() $this->assertTrue($kernel->getContainer()->getParameter('test.processed')); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage "123" is not a valid kernel name. + */ + public function testInvalidKernelName() + { + new KernelForTest('dev', true, '123'); + } + /** * Returns a mock for the BundleInterface. * @@ -895,7 +908,7 @@ protected function getKernel(array $methods = array(), array $bundles = array()) $kernel = $this ->getMockBuilder('Symfony\Component\HttpKernel\Kernel') ->setMethods($methods) - ->setConstructorArgs(array('test', false)) + ->setConstructorArgs(array('test', false, 'app')) ->getMockForAbstractClass() ; $kernel->expects($this->any()) @@ -944,7 +957,7 @@ class CustomProjectDirKernel extends Kernel public function __construct(\Closure $buildContainer = null) { - parent::__construct('custom', true); + parent::__construct('custom', true, 'app'); $this->baseDir = 'foo'; $this->buildContainer = $buildContainer; @@ -982,7 +995,7 @@ class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface public function __construct(\Closure $buildContainer = null) { parent::__construct(); - Kernel::__construct('pass', true); + Kernel::__construct('pass', true, 'app'); } public function process(ContainerBuilder $container)