Permalink
Browse files

feature #28810 [HttpKernel] Deprecate usage of getRootDir() and kerne…

…l.root_dir (fabpot)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[HttpKernel] Deprecate usage of getRootDir() and kernel.root_dir

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #24293
| License       | MIT
| Doc PR        | n/a

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest 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.
-->

Commits
-------

0b851c6 [HttpKernel] deprecated usage of getRootDir() and kernel.root_dir
  • Loading branch information...
fabpot committed Oct 16, 2018
2 parents 3accf51 + 0b851c6 commit e85f6d4e0860ffbfd9911a1c6da6cf5379b5f790
Showing with 106 additions and 116 deletions.
  1. +6 −0 UPGRADE-5.0.md
  2. +1 −1 src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php
  3. +1 −1 src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php
  4. +0 −1 src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
  5. +6 −6 src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php
  6. +4 −4 src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php
  7. +14 −6 src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php
  8. +5 −5 src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php
  9. +12 −2 src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php
  10. +1 −1 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php
  11. +3 −3 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php
  12. +2 −2 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php
  13. +1 −1 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml
  14. +2 −2 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php
  15. +1 −1 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml
  16. +1 −1 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml
  17. +1 −1 src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php
  18. +1 −1 src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolClearerPassTest.php
  19. +3 −3 src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php
  20. +1 −0 src/Symfony/Component/HttpKernel/CHANGELOG.md
  21. +17 −5 src/Symfony/Component/HttpKernel/Kernel.php
  22. +0 −37 src/Symfony/Component/HttpKernel/Tests/Fixtures/123/Kernel123.php
  23. +10 −0 src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php
  24. +13 −32 src/Symfony/Component/HttpKernel/Tests/KernelTest.php
@@ -177,6 +177,12 @@ HttpFoundation
* The default value of the "$secure" and "$samesite" arguments of Cookie's constructor
changed respectively from "false" to "null" and from "null" to "lax".
HttpKernel
----------
* The `Kernel::getRootDir()` and the `kernel.root_dir` parameter have been removed
* The `KernelInterface::getName()` and the `kernel.name` parameter have been removed
Monolog
-------
@@ -365,7 +365,7 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
if ($container->hasParameter('cache.prefix.seed')) {
$seed = '.'.$container->getParameterBag()->resolveValue($container->getParameter('cache.prefix.seed'));
} else {
$seed = '_'.$container->getParameter('kernel.root_dir');
$seed = '_'.$container->getParameter('kernel.project_dir');
}
$seed .= '.'.$container->getParameter('kernel.container_class').'.'.$container->getParameter('kernel.environment').'.'.$container->getParameter('kernel.debug');
$namespace = 'sf_'.$this->getMappingResourceExtension().'_'.$objectManagerName.'_'.ContainerBuilder::hash($seed);
@@ -272,7 +272,7 @@ protected function createContainer(array $data = array())
'kernel.debug' => false,
'kernel.environment' => 'test',
'kernel.container_class' => 'kernel',
'kernel.root_dir' => __DIR__,
'kernel.project_dir' => __DIR__,
), $data)));
}
}
@@ -74,7 +74,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
array('Environment', $kernel->getEnvironment()),
array('Debug', $kernel->isDebug() ? 'true' : 'false'),
array('Charset', $kernel->getCharset()),
array('Root directory', self::formatPath($kernel->getRootDir(), $kernel->getProjectDir())),
array('Cache directory', self::formatPath($kernel->getCacheDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'),
array('Log directory', self::formatPath($kernel->getLogDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getLogDir()).'</>)'),
new TableSeparator(),
@@ -130,11 +130,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$kernel = $this->getApplication()->getKernel();
// Define Root Paths
$transPaths = array($kernel->getRootDir().'/Resources/translations');
$transPaths = array($kernel->getRootDir(false).'/Resources/translations');
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
$viewsPaths = array($kernel->getRootDir().'/Resources/views');
$viewsPaths = array($kernel->getRootDir(false).'/Resources/views');
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
}
@@ -147,12 +147,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
}
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $bundle->getName());
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(false), $bundle->getName());
$viewsPaths = array($bundle->getPath().'/Resources/views');
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
}
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $bundle->getName());
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(false), $bundle->getName());
} catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
@@ -168,12 +168,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
}
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $bundle->getName());
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(false), $bundle->getName());
$viewsPaths[] = $bundle->getPath().'/Resources/views';
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
}
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $bundle->getName());
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(false), $bundle->getName());
}
}
@@ -120,11 +120,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$kernel = $this->getApplication()->getKernel();
// Define Root Paths
$transPaths = array($kernel->getRootDir().'/Resources/translations');
$transPaths = array($kernel->getRootDir(false).'/Resources/translations');
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
$viewsPaths = array($kernel->getRootDir().'/Resources/views');
$viewsPaths = array($kernel->getRootDir(false).'/Resources/views');
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
}
@@ -138,12 +138,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath.'/'.$foundBundle->getName();
}
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $foundBundle->getName());
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(false), $foundBundle->getName());
$viewsPaths = array($foundBundle->getPath().'/Resources/views');
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$foundBundle->getName();
}
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $foundBundle->getName());
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(false), $foundBundle->getName());
$currentName = $foundBundle->getName();
} catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path
@@ -16,22 +16,30 @@
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @internal
*/
class CodeHelper extends Helper
{
protected $fileLinkFormat;
/**
* @deprecated since Symfony 4.2
*/
protected $rootDir;
protected $charset;
private $projectDir;
/**
* @param string|FileLinkFormatter $fileLinkFormat The format for links to source files
* @param string $rootDir The project root directory
* @param string $projectDir The project root directory
* @param string $charset The charset
*/
public function __construct($fileLinkFormat, string $rootDir, string $charset)
public function __construct($fileLinkFormat, string $projectDir, string $charset)
{
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
$this->rootDir = str_replace('\\', '/', $rootDir).'/';
$this->projectDir = str_replace('\\', '/', $projectDir).'/';
$this->rootDir = $this->projectDir;
$this->charset = $charset;
}
@@ -156,10 +164,10 @@ public function formatFile($file, $line, $text = null)
if (null === $text) {
$file = trim($file);
$fileStr = $file;
if (0 === strpos($fileStr, $this->rootDir)) {
$fileStr = str_replace(array('\\', $this->rootDir), array('/', ''), $fileStr);
if (0 === strpos($fileStr, $this->projectDir)) {
$fileStr = str_replace(array('\\', $this->projectDir), array('/', ''), $fileStr);
$fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);
$fileStr = sprintf('<abbr title="%s">kernel.project_dir</abbr>/%s', htmlspecialchars($this->projectDir, $flags, $this->charset), $fileStr);
}
$text = sprintf('%s at line %d', $fileStr, $line);
@@ -27,20 +27,20 @@ class CacheClearCommandTest extends TestCase
private $kernel;
/** @var Filesystem */
private $fs;
private $rootDir;
private $projectDir;
protected function setUp()
{
$this->fs = new Filesystem();
$this->kernel = new TestAppKernel('test', true);
$this->rootDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('sf_cache_', true);
$this->kernel->setRootDir($this->rootDir);
$this->fs->mkdir($this->rootDir);
$this->projectDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('sf_cache_', true);
$this->kernel->setProjectDir($this->projectDir);
$this->fs->mkdir($this->projectDir);
}
protected function tearDown()
{
$this->fs->remove($this->rootDir);
$this->fs->remove($this->projectDir);
}
public function testCacheIsFreshAfterCacheClearedWithWarmup()
@@ -26,9 +26,19 @@ public function registerBundles()
);
}
public function setRootDir($rootDir)
public function setProjectDir($projectDir)
{
$this->rootDir = $rootDir;
$this->projectDir = $projectDir;
}
public function getCacheDir()
{
return $this->getProjectDir().'/Tests/Fixtures/cache.'.$this->environment;
}
public function getLogDir()
{
return $this->getProjectDir().'/Tests/Fixtures/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
@@ -32,7 +32,7 @@ public function testPoolRefsAreWeak()
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', 'foo');
$container->setParameter('kernel.project_dir', 'foo');
$globalClearer = new Definition(Psr6CacheClearer::class);
$container->setDefinition('cache.global_clearer', $globalClearer);
@@ -37,7 +37,7 @@ public function testNamespaceArgumentIsReplaced()
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', 'foo');
$container->setParameter('kernel.project_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
$adapter->addTag('cache.pool');
@@ -58,7 +58,7 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
$container = new ContainerBuilder();
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.root_dir', 'foo');
$container->setParameter('kernel.project_dir', 'foo');
$container->register('cache.adapter.array', ArrayAdapter::class)->addArgument(0);
@@ -128,7 +128,7 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', 'foo');
$container->setParameter('kernel.project_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
$adapter->addTag('cache.pool');
@@ -47,14 +47,14 @@ public function __construct($varDir, $testCase, $rootConfig, $environment, $debu
public function registerBundles()
{
if (!file_exists($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
if (!file_exists($filename = $this->getProjectDir().'/'.$this->testCase.'/bundles.php')) {
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
}
return include $filename;
}
public function getRootDir()
public function getProjectDir()
{
return __DIR__;
}
@@ -1,6 +1,6 @@
framework:
secret: test
router: { resource: "%kernel.root_dir%/%kernel.test_case%/routing.yml" }
router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml" }
validation: { enabled: true, enable_annotations: true }
csrf_protection: true
form: true
@@ -53,14 +53,14 @@ public function getContainerClass()
public function registerBundles()
{
if (!is_file($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
if (!is_file($filename = $this->getProjectDir().'/'.$this->testCase.'/bundles.php')) {
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
}
return include $filename;
}
public function getRootDir()
public function getProjectDir()
{
return __DIR__;
}
@@ -1,6 +1,6 @@
framework:
secret: test
router: { resource: "%kernel.root_dir%/%kernel.test_case%/routing.yml" }
router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml" }
validation: { enabled: true, enable_annotations: true }
csrf_protection: true
form: true
@@ -1,6 +1,6 @@
framework:
secret: test
router: { resource: "%kernel.root_dir%/%kernel.test_case%/routing.yml" }
router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml" }
validation: { enabled: true, enable_annotations: true }
assets: ~
csrf_protection: true
@@ -50,7 +50,7 @@ public function process(ContainerBuilder $container)
if ($container->hasParameter('cache.prefix.seed')) {
$seed = '.'.$container->getParameterBag()->resolveValue($container->getParameter('cache.prefix.seed'));
} else {
$seed = '_'.$container->getParameter('kernel.root_dir');
$seed = '_'.$container->getParameter('kernel.project_dir');
}
$seed .= '.'.$container->getParameter('kernel.container_class').'.'.$container->getParameter('kernel.environment');
@@ -29,7 +29,7 @@ public function testPoolRefsAreWeak()
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', 'foo');
$container->setParameter('kernel.project_dir', 'foo');
$globalClearer = new Definition(Psr6CacheClearer::class);
$container->setDefinition('cache.global_clearer', $globalClearer);
@@ -34,7 +34,7 @@ public function testNamespaceArgumentIsReplaced()
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', 'foo');
$container->setParameter('kernel.project_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
$adapter->addTag('cache.pool');
@@ -55,7 +55,7 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
$container = new ContainerBuilder();
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.root_dir', 'foo');
$container->setParameter('kernel.project_dir', 'foo');
$container->register('cache.adapter.array', ArrayAdapter::class)->addArgument(0);
@@ -125,7 +125,7 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', 'foo');
$container->setParameter('kernel.project_dir', 'foo');
$adapter = new Definition();
$adapter->setAbstract(true);
$adapter->addTag('cache.pool');
@@ -4,6 +4,7 @@ CHANGELOG
4.2.0
-----
* deprecated `Kernel::getRootDir()` and the `kernel.root_dir` parameter
* deprecated `KernelInterface::getName()` and the `kernel.name` parameter
4.1.0
Oops, something went wrong.

0 comments on commit e85f6d4

Please sign in to comment.