Skip to content

Commit 48351d5

Browse files
Simperfitnicolas-grekas
authored andcommitted
[HttpKernel] remove all deprecated code from http kernel
1 parent ceb40c1 commit 48351d5

File tree

8 files changed

+9
-198
lines changed

8 files changed

+9
-198
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php

-5
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ function ($path, $catalogue) use ($loadedMessages) {
157157
->willReturnMap($returnValues);
158158
}
159159

160-
$kernel
161-
->expects($this->any())
162-
->method('getRootDir')
163-
->willReturn($this->translationDir);
164-
165160
$kernel
166161
->expects($this->any())
167162
->method('getBundles')

src/Symfony/Bundle/TwigBundle/Resources/config/console.xml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<argument>%kernel.bundles_metadata%</argument>
1414
<argument>%twig.default_path%</argument>
1515
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
16-
<argument>%kernel.root_dir%</argument>
1716
<tag name="console.command" command="debug:twig" />
1817
</service>
1918

src/Symfony/Component/HttpKernel/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* removed `ConfigDataCollector::getApplicationVersion()`
1010
* removed support for `Symfony\Component\Templating\EngineInterface` in `HIncludeFragmentRenderer`, use a `Twig\Environment` only
1111
* removed `TranslatorListener` in favor of `LocaleAwareListener`
12+
* removed `getRootDir()` and `getName()` from `Kernel` and `KernelInterface`
1213
* removed `FilterControllerArgumentsEvent`, use `ControllerArgumentsEvent` instead
1314
* removed `FilterControllerEvent`, use `ControllerEvent` instead
1415
* removed `FilterResponseEvent`, use `ResponseEvent` instead

src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

-14
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,6 @@ public function getPhpTimezone()
211211
return $this->data['php_timezone'];
212212
}
213213

214-
/**
215-
* Gets the application name.
216-
*
217-
* @return string The application name
218-
*
219-
* @deprecated since Symfony 4.2
220-
*/
221-
public function getAppName()
222-
{
223-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
224-
225-
return 'n/a';
226-
}
227-
228214
/**
229215
* Gets the environment.
230216
*

src/Symfony/Component/HttpKernel/Kernel.php

+5-92
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
5555
protected $bundles = [];
5656

5757
protected $container;
58-
/**
59-
* @deprecated since Symfony 4.2
60-
*/
61-
protected $rootDir;
6258
protected $environment;
6359
protected $debug;
6460
protected $booted = false;
65-
/**
66-
* @deprecated since Symfony 4.2
67-
*/
68-
protected $name;
6961
protected $startTime;
7062

7163
private $projectDir;
@@ -87,8 +79,6 @@ public function __construct(string $environment, bool $debug)
8779
{
8880
$this->environment = $environment;
8981
$this->debug = $debug;
90-
$this->rootDir = $this->getRootDir(false);
91-
$this->name = $this->getName(false);
9282
}
9383

9484
public function __clone()
@@ -278,27 +268,6 @@ public function locateResource($name, $dir = null, $first = true)
278268
throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
279269
}
280270

281-
/**
282-
* {@inheritdoc}
283-
*
284-
* @deprecated since Symfony 4.2
285-
*/
286-
public function getName(/* $triggerDeprecation = true */)
287-
{
288-
if (0 === \func_num_args() || func_get_arg(0)) {
289-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
290-
}
291-
292-
if (null === $this->name) {
293-
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
294-
if (ctype_digit($this->name[0])) {
295-
$this->name = '_'.$this->name;
296-
}
297-
}
298-
299-
return $this->name;
300-
}
301-
302271
/**
303272
* {@inheritdoc}
304273
*/
@@ -315,25 +284,6 @@ public function isDebug()
315284
return $this->debug;
316285
}
317286

318-
/**
319-
* {@inheritdoc}
320-
*
321-
* @deprecated since Symfony 4.2, use getProjectDir() instead
322-
*/
323-
public function getRootDir(/* $triggerDeprecation = true */)
324-
{
325-
if (0 === \func_num_args() || func_get_arg(0)) {
326-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use getProjectDir() instead.', __METHOD__), E_USER_DEPRECATED);
327-
}
328-
329-
if (null === $this->rootDir) {
330-
$r = new \ReflectionObject($this);
331-
$this->rootDir = \dirname($r->getFileName());
332-
}
333-
334-
return $this->rootDir;
335-
}
336-
337287
/**
338288
* Gets the application root dir (path of the project's composer file).
339289
*
@@ -450,8 +400,7 @@ protected function getContainerClass()
450400
{
451401
$class = \get_class($this);
452402
$class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).str_replace('.', '_', ContainerBuilder::hash($class)) : $class;
453-
$class = $this->name.str_replace('\\', '_', $class).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container';
454-
403+
$class = str_replace('\\', '_', $class).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container';
455404
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) {
456405
throw new \InvalidArgumentException(sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', $this->environment));
457406
}
@@ -611,18 +560,17 @@ protected function getKernelParameters()
611560
];
612561
}
613562

563+
$rootDir = new \ReflectionObject($this);
564+
$rootDir = \dirname($rootDir->getFileName());
565+
614566
return [
615567
/*
616568
* @deprecated since Symfony 4.2, use kernel.project_dir instead
617569
*/
618-
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
570+
'kernel.root_dir' => realpath($rootDir) ?: $rootDir,
619571
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
620572
'kernel.environment' => $this->environment,
621573
'kernel.debug' => $this->debug,
622-
/*
623-
* @deprecated since Symfony 4.2
624-
*/
625-
'kernel.name' => $this->name,
626574
'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
627575
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
628576
'kernel.bundles' => $bundles,
@@ -837,48 +785,13 @@ public static function stripComments($source)
837785
return $output;
838786
}
839787

840-
/**
841-
* @deprecated since Symfony 4.3
842-
*/
843-
public function serialize()
844-
{
845-
@trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);
846-
847-
return serialize([$this->environment, $this->debug]);
848-
}
849-
850-
/**
851-
* @deprecated since Symfony 4.3
852-
*/
853-
public function unserialize($data)
854-
{
855-
@trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);
856-
list($environment, $debug) = unserialize($data, ['allowed_classes' => false]);
857-
858-
$this->__construct($environment, $debug);
859-
}
860-
861788
public function __sleep()
862789
{
863-
if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'serialize'))->getDeclaringClass()->name) {
864-
@trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3.', $c), E_USER_DEPRECATED);
865-
$this->serialized = $this->serialize();
866-
867-
return ['serialized'];
868-
}
869-
870790
return ['environment', 'debug'];
871791
}
872792

873793
public function __wakeup()
874794
{
875-
if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'serialize'))->getDeclaringClass()->name) {
876-
@trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3.', $c), E_USER_DEPRECATED);
877-
$this->unserialize($this->serialized);
878-
unset($this->serialized);
879-
880-
return;
881-
}
882795
$this->__construct($this->environment, $this->debug);
883796
}
884797
}

src/Symfony/Component/HttpKernel/KernelInterface.php

-18
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ public function getBundle($name);
9696
*/
9797
public function locateResource($name, $dir = null, $first = true);
9898

99-
/**
100-
* Gets the name of the kernel.
101-
*
102-
* @return string The kernel name
103-
*
104-
* @deprecated since Symfony 4.2
105-
*/
106-
public function getName();
107-
10899
/**
109100
* Gets the environment.
110101
*
@@ -119,15 +110,6 @@ public function getEnvironment();
119110
*/
120111
public function isDebug();
121112

122-
/**
123-
* Gets the application root dir (path of the project's Kernel class).
124-
*
125-
* @return string The Kernel root dir
126-
*
127-
* @deprecated since Symfony 4.2
128-
*/
129-
public function getRootDir();
130-
131113
/**
132114
* Gets the project dir (path of the project's composer file).
133115
*

src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForOverrideName.php

-28
This file was deleted.

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

+3-40
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
2424
use Symfony\Component\HttpKernel\HttpKernelInterface;
2525
use Symfony\Component\HttpKernel\Kernel;
26-
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;
2726
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
2827
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelWithoutBundles;
2928
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
@@ -89,7 +88,7 @@ public function testInitializeContainerClearsOldContainers()
8988
$kernel->boot();
9089

9190
$containerDir = __DIR__.'/Fixtures/var/cache/custom/'.substr(\get_class($kernel->getContainer()), 0, 16);
92-
$this->assertTrue(unlink(__DIR__.'/Fixtures/var/cache/custom/TestsSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta'));
91+
$this->assertTrue(unlink(__DIR__.'/Fixtures/var/cache/custom/Symfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta'));
9392
$this->assertFileExists($containerDir);
9493
$this->assertFileNotExists($containerDir.'.legacy');
9594

@@ -309,36 +308,6 @@ public function doStuff()
309308
$this->assertEquals($expected, $output);
310309
}
311310

312-
/**
313-
* @group legacy
314-
*/
315-
public function testGetRootDir()
316-
{
317-
$kernel = new KernelForTest('test', true);
318-
319-
$this->assertEquals(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures', realpath($kernel->getRootDir()));
320-
}
321-
322-
/**
323-
* @group legacy
324-
*/
325-
public function testGetName()
326-
{
327-
$kernel = new KernelForTest('test', true);
328-
329-
$this->assertEquals('Fixtures', $kernel->getName());
330-
}
331-
332-
/**
333-
* @group legacy
334-
*/
335-
public function testOverrideGetName()
336-
{
337-
$kernel = new KernelForOverrideName('test', true);
338-
339-
$this->assertEquals('overridden', $kernel->getName());
340-
}
341-
342311
public function testSerialize()
343312
{
344313
$env = 'test_env';
@@ -546,14 +515,14 @@ public function testKernelReset()
546515

547516
$containerClass = \get_class($kernel->getContainer());
548517
$containerFile = (new \ReflectionClass($kernel->getContainer()))->getFileName();
549-
unlink(__DIR__.'/Fixtures/var/cache/custom/TestsSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');
518+
unlink(__DIR__.'/Fixtures/var/cache/custom/Symfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');
550519

551520
$kernel = new CustomProjectDirKernel();
552521
$kernel->boot();
553522

554523
$this->assertInstanceOf($containerClass, $kernel->getContainer());
555524
$this->assertFileExists($containerFile);
556-
unlink(__DIR__.'/Fixtures/var/cache/custom/TestsSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');
525+
unlink(__DIR__.'/Fixtures/var/cache/custom/Symfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta');
557526

558527
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
559528
$kernel->boot();
@@ -680,9 +649,6 @@ protected function getKernel(array $methods = [], array $bundles = [])
680649
->method('registerBundles')
681650
->willReturn($bundles)
682651
;
683-
$p = new \ReflectionProperty($kernel, 'rootDir');
684-
$p->setAccessible(true);
685-
$p->setValue($kernel, __DIR__.'/Fixtures');
686652

687653
return $kernel;
688654
}
@@ -693,9 +659,6 @@ protected function getKernelForTest(array $methods = [], $debug = false)
693659
->setConstructorArgs(['test', $debug])
694660
->setMethods($methods)
695661
->getMock();
696-
$p = new \ReflectionProperty($kernel, 'rootDir');
697-
$p->setAccessible(true);
698-
$p->setValue($kernel, __DIR__.'/Fixtures');
699662

700663
return $kernel;
701664
}

0 commit comments

Comments
 (0)