Skip to content

Commit

Permalink
minor #31672 [HttpKernel] remove all deprecated code from http kernel…
Browse files Browse the repository at this point in the history
… (Simperfit)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[HttpKernel] remove all deprecated code from http kernel

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | none   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        |to check<!-- required for new features -->

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->
REmove all deprecated code from HttpKernel, update all listener and all tests

Commits
-------

48351d5 [HttpKernel] remove all deprecated code from http kernel
  • Loading branch information
nicolas-grekas committed Jun 8, 2019
2 parents ceb40c1 + 48351d5 commit 0f35e5b
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 198 deletions.
Expand Up @@ -157,11 +157,6 @@ function ($path, $catalogue) use ($loadedMessages) {
->willReturnMap($returnValues);
}

$kernel
->expects($this->any())
->method('getRootDir')
->willReturn($this->translationDir);

$kernel
->expects($this->any())
->method('getBundles')
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/console.xml
Expand Up @@ -13,7 +13,6 @@
<argument>%kernel.bundles_metadata%</argument>
<argument>%twig.default_path%</argument>
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
<argument>%kernel.root_dir%</argument>
<tag name="console.command" command="debug:twig" />
</service>

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ CHANGELOG
* removed `ConfigDataCollector::getApplicationVersion()`
* removed support for `Symfony\Component\Templating\EngineInterface` in `HIncludeFragmentRenderer`, use a `Twig\Environment` only
* removed `TranslatorListener` in favor of `LocaleAwareListener`
* removed `getRootDir()` and `getName()` from `Kernel` and `KernelInterface`
* removed `FilterControllerArgumentsEvent`, use `ControllerArgumentsEvent` instead
* removed `FilterControllerEvent`, use `ControllerEvent` instead
* removed `FilterResponseEvent`, use `ResponseEvent` instead
Expand Down
Expand Up @@ -211,20 +211,6 @@ public function getPhpTimezone()
return $this->data['php_timezone'];
}

/**
* Gets the application name.
*
* @return string The application name
*
* @deprecated since Symfony 4.2
*/
public function getAppName()
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);

return 'n/a';
}

/**
* Gets the environment.
*
Expand Down
97 changes: 5 additions & 92 deletions src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -55,17 +55,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
protected $bundles = [];

protected $container;
/**
* @deprecated since Symfony 4.2
*/
protected $rootDir;
protected $environment;
protected $debug;
protected $booted = false;
/**
* @deprecated since Symfony 4.2
*/
protected $name;
protected $startTime;

private $projectDir;
Expand All @@ -87,8 +79,6 @@ public function __construct(string $environment, bool $debug)
{
$this->environment = $environment;
$this->debug = $debug;
$this->rootDir = $this->getRootDir(false);
$this->name = $this->getName(false);
}

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

/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.2
*/
public function getName(/* $triggerDeprecation = true */)
{
if (0 === \func_num_args() || func_get_arg(0)) {
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
}

if (null === $this->name) {
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir));
if (ctype_digit($this->name[0])) {
$this->name = '_'.$this->name;
}
}

return $this->name;
}

/**
* {@inheritdoc}
*/
Expand All @@ -315,25 +284,6 @@ public function isDebug()
return $this->debug;
}

/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.2, use getProjectDir() instead
*/
public function getRootDir(/* $triggerDeprecation = true */)
{
if (0 === \func_num_args() || func_get_arg(0)) {
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use getProjectDir() instead.', __METHOD__), E_USER_DEPRECATED);
}

if (null === $this->rootDir) {
$r = new \ReflectionObject($this);
$this->rootDir = \dirname($r->getFileName());
}

return $this->rootDir;
}

/**
* Gets the application root dir (path of the project's composer file).
*
Expand Down Expand Up @@ -450,8 +400,7 @@ protected function getContainerClass()
{
$class = \get_class($this);
$class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).str_replace('.', '_', ContainerBuilder::hash($class)) : $class;
$class = $this->name.str_replace('\\', '_', $class).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container';

$class = str_replace('\\', '_', $class).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container';
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) {
throw new \InvalidArgumentException(sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', $this->environment));
}
Expand Down Expand Up @@ -611,18 +560,17 @@ protected function getKernelParameters()
];
}

$rootDir = new \ReflectionObject($this);
$rootDir = \dirname($rootDir->getFileName());

return [
/*
* @deprecated since Symfony 4.2, use kernel.project_dir instead
*/
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
'kernel.root_dir' => realpath($rootDir) ?: $rootDir,
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
'kernel.environment' => $this->environment,
'kernel.debug' => $this->debug,
/*
* @deprecated since Symfony 4.2
*/
'kernel.name' => $this->name,
'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
'kernel.bundles' => $bundles,
Expand Down Expand Up @@ -837,48 +785,13 @@ public static function stripComments($source)
return $output;
}

/**
* @deprecated since Symfony 4.3
*/
public function serialize()
{
@trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);

return serialize([$this->environment, $this->debug]);
}

/**
* @deprecated since Symfony 4.3
*/
public function unserialize($data)
{
@trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.3.', __METHOD__), E_USER_DEPRECATED);
list($environment, $debug) = unserialize($data, ['allowed_classes' => false]);

$this->__construct($environment, $debug);
}

public function __sleep()
{
if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'serialize'))->getDeclaringClass()->name) {
@trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3.', $c), E_USER_DEPRECATED);
$this->serialized = $this->serialize();

return ['serialized'];
}

return ['environment', 'debug'];
}

public function __wakeup()
{
if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'serialize'))->getDeclaringClass()->name) {
@trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3.', $c), E_USER_DEPRECATED);
$this->unserialize($this->serialized);
unset($this->serialized);

return;
}
$this->__construct($this->environment, $this->debug);
}
}
18 changes: 0 additions & 18 deletions src/Symfony/Component/HttpKernel/KernelInterface.php
Expand Up @@ -96,15 +96,6 @@ public function getBundle($name);
*/
public function locateResource($name, $dir = null, $first = true);

/**
* Gets the name of the kernel.
*
* @return string The kernel name
*
* @deprecated since Symfony 4.2
*/
public function getName();

/**
* Gets the environment.
*
Expand All @@ -119,15 +110,6 @@ public function getEnvironment();
*/
public function isDebug();

/**
* Gets the application root dir (path of the project's Kernel class).
*
* @return string The Kernel root dir
*
* @deprecated since Symfony 4.2
*/
public function getRootDir();

/**
* Gets the project dir (path of the project's composer file).
*
Expand Down

This file was deleted.

43 changes: 3 additions & 40 deletions src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Expand Up @@ -23,7 +23,6 @@
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelWithoutBundles;
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
Expand Down Expand Up @@ -89,7 +88,7 @@ public function testInitializeContainerClearsOldContainers()
$kernel->boot();

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

Expand Down Expand Up @@ -309,36 +308,6 @@ public function doStuff()
$this->assertEquals($expected, $output);
}

/**
* @group legacy
*/
public function testGetRootDir()
{
$kernel = new KernelForTest('test', true);

$this->assertEquals(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures', realpath($kernel->getRootDir()));
}

/**
* @group legacy
*/
public function testGetName()
{
$kernel = new KernelForTest('test', true);

$this->assertEquals('Fixtures', $kernel->getName());
}

/**
* @group legacy
*/
public function testOverrideGetName()
{
$kernel = new KernelForOverrideName('test', true);

$this->assertEquals('overridden', $kernel->getName());
}

public function testSerialize()
{
$env = 'test_env';
Expand Down Expand Up @@ -546,14 +515,14 @@ public function testKernelReset()

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

$kernel = new CustomProjectDirKernel();
$kernel->boot();

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

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

return $kernel;
}
Expand All @@ -693,9 +659,6 @@ protected function getKernelForTest(array $methods = [], $debug = false)
->setConstructorArgs(['test', $debug])
->setMethods($methods)
->getMock();
$p = new \ReflectionProperty($kernel, 'rootDir');
$p->setAccessible(true);
$p->setValue($kernel, __DIR__.'/Fixtures');

return $kernel;
}
Expand Down

0 comments on commit 0f35e5b

Please sign in to comment.