Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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');
Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,30 @@

/**
* @author Fabien Potencier <[email protected]>
*
* @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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already inject kernel.project_dir in the container definition.

{
$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;
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading