Skip to content

Commit af9f2c2

Browse files
committed
[HttpKernel] deprecated usage of getRootDir() and kernel.root_dir
1 parent 171698d commit af9f2c2

File tree

10 files changed

+48
-31
lines changed

10 files changed

+48
-31
lines changed

Command/AboutCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
7474
array('Environment', $kernel->getEnvironment()),
7575
array('Debug', $kernel->isDebug() ? 'true' : 'false'),
7676
array('Charset', $kernel->getCharset()),
77-
array('Root directory', self::formatPath($kernel->getRootDir(), $kernel->getProjectDir())),
7877
array('Cache directory', self::formatPath($kernel->getCacheDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'),
7978
array('Log directory', self::formatPath($kernel->getLogDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getLogDir()).'</>)'),
8079
new TableSeparator(),

Command/TranslationDebugCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
130130
$kernel = $this->getApplication()->getKernel();
131131

132132
// Define Root Paths
133-
$transPaths = array($kernel->getRootDir().'/Resources/translations');
133+
$transPaths = array($kernel->getRootDir(false).'/Resources/translations');
134134
if ($this->defaultTransPath) {
135135
$transPaths[] = $this->defaultTransPath;
136136
}
137-
$viewsPaths = array($kernel->getRootDir().'/Resources/views');
137+
$viewsPaths = array($kernel->getRootDir(false).'/Resources/views');
138138
if ($this->defaultViewsPath) {
139139
$viewsPaths[] = $this->defaultViewsPath;
140140
}
@@ -147,12 +147,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
147147
if ($this->defaultTransPath) {
148148
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
149149
}
150-
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $bundle->getName());
150+
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(false), $bundle->getName());
151151
$viewsPaths = array($bundle->getPath().'/Resources/views');
152152
if ($this->defaultViewsPath) {
153153
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
154154
}
155-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $bundle->getName());
155+
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(false), $bundle->getName());
156156
} catch (\InvalidArgumentException $e) {
157157
// such a bundle does not exist, so treat the argument as path
158158
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
@@ -168,12 +168,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
168168
if ($this->defaultTransPath) {
169169
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
170170
}
171-
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $bundle->getName());
171+
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(false), $bundle->getName());
172172
$viewsPaths[] = $bundle->getPath().'/Resources/views';
173173
if ($this->defaultViewsPath) {
174174
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
175175
}
176-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $bundle->getName());
176+
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(false), $bundle->getName());
177177
}
178178
}
179179

Command/TranslationUpdateCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
120120
$kernel = $this->getApplication()->getKernel();
121121

122122
// Define Root Paths
123-
$transPaths = array($kernel->getRootDir().'/Resources/translations');
123+
$transPaths = array($kernel->getRootDir(false).'/Resources/translations');
124124
if ($this->defaultTransPath) {
125125
$transPaths[] = $this->defaultTransPath;
126126
}
127-
$viewsPaths = array($kernel->getRootDir().'/Resources/views');
127+
$viewsPaths = array($kernel->getRootDir(false).'/Resources/views');
128128
if ($this->defaultViewsPath) {
129129
$viewsPaths[] = $this->defaultViewsPath;
130130
}
@@ -138,12 +138,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
138138
if ($this->defaultTransPath) {
139139
$transPaths[] = $this->defaultTransPath.'/'.$foundBundle->getName();
140140
}
141-
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $foundBundle->getName());
141+
$transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(false), $foundBundle->getName());
142142
$viewsPaths = array($foundBundle->getPath().'/Resources/views');
143143
if ($this->defaultViewsPath) {
144144
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$foundBundle->getName();
145145
}
146-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $foundBundle->getName());
146+
$viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(false), $foundBundle->getName());
147147
$currentName = $foundBundle->getName();
148148
} catch (\InvalidArgumentException $e) {
149149
// such a bundle does not exist, so treat the argument as path

Templating/Helper/CodeHelper.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,30 @@
1616

1717
/**
1818
* @author Fabien Potencier <fabien@symfony.com>
19+
*
20+
* @internal
1921
*/
2022
class CodeHelper extends Helper
2123
{
2224
protected $fileLinkFormat;
25+
/**
26+
* @deprecated since Symfony 4.2
27+
*/
2328
protected $rootDir;
2429
protected $charset;
2530

31+
private $projectDir;
32+
2633
/**
2734
* @param string|FileLinkFormatter $fileLinkFormat The format for links to source files
28-
* @param string $rootDir The project root directory
35+
* @param string $projectDir The project root directory
2936
* @param string $charset The charset
3037
*/
31-
public function __construct($fileLinkFormat, string $rootDir, string $charset)
38+
public function __construct($fileLinkFormat, string $projectDir, string $charset)
3239
{
3340
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
34-
$this->rootDir = str_replace('\\', '/', $rootDir).'/';
41+
$this->projectDir = str_replace('\\', '/', $projectDir).'/';
42+
$this->rootDir = $this->projectDir;
3543
$this->charset = $charset;
3644
}
3745

@@ -156,10 +164,10 @@ public function formatFile($file, $line, $text = null)
156164
if (null === $text) {
157165
$file = trim($file);
158166
$fileStr = $file;
159-
if (0 === strpos($fileStr, $this->rootDir)) {
160-
$fileStr = str_replace(array('\\', $this->rootDir), array('/', ''), $fileStr);
167+
if (0 === strpos($fileStr, $this->projectDir)) {
168+
$fileStr = str_replace(array('\\', $this->projectDir), array('/', ''), $fileStr);
161169
$fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
162-
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);
170+
$fileStr = sprintf('<abbr title="%s">kernel.project_dir</abbr>/%s', htmlspecialchars($this->projectDir, $flags, $this->charset), $fileStr);
163171
}
164172

165173
$text = sprintf('%s at line %d', $fileStr, $line);

Tests/Command/CacheClearCommand/CacheClearCommandTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ class CacheClearCommandTest extends TestCase
2727
private $kernel;
2828
/** @var Filesystem */
2929
private $fs;
30-
private $rootDir;
30+
private $projectDir;
3131

3232
protected function setUp()
3333
{
3434
$this->fs = new Filesystem();
3535
$this->kernel = new TestAppKernel('test', true);
36-
$this->rootDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('sf_cache_', true);
37-
$this->kernel->setRootDir($this->rootDir);
38-
$this->fs->mkdir($this->rootDir);
36+
$this->projectDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('sf_cache_', true);
37+
$this->kernel->setProjectDir($this->projectDir);
38+
$this->fs->mkdir($this->projectDir);
3939
}
4040

4141
protected function tearDown()
4242
{
43-
$this->fs->remove($this->rootDir);
43+
$this->fs->remove($this->projectDir);
4444
}
4545

4646
public function testCacheIsFreshAfterCacheClearedWithWarmup()

Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,19 @@ public function registerBundles()
2626
);
2727
}
2828

29-
public function setRootDir($rootDir)
29+
public function setProjectDir($projectDir)
3030
{
31-
$this->rootDir = $rootDir;
31+
$this->projectDir = $projectDir;
32+
}
33+
34+
public function getCacheDir()
35+
{
36+
return $this->getProjectDir().'/Tests/Fixtures/cache.'.$this->environment;
37+
}
38+
39+
public function getLogDir()
40+
{
41+
return $this->getProjectDir().'/Tests/Fixtures/logs';
3242
}
3343

3444
public function registerContainerConfiguration(LoaderInterface $loader)

Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testPoolRefsAreWeak()
3232
$container->setParameter('kernel.debug', false);
3333
$container->setParameter('kernel.container_class', 'app');
3434
$container->setParameter('kernel.environment', 'prod');
35-
$container->setParameter('kernel.root_dir', 'foo');
35+
$container->setParameter('kernel.project_dir', 'foo');
3636

3737
$globalClearer = new Definition(Psr6CacheClearer::class);
3838
$container->setDefinition('cache.global_clearer', $globalClearer);

Tests/DependencyInjection/Compiler/CachePoolPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testNamespaceArgumentIsReplaced()
3737
$container->setParameter('kernel.debug', false);
3838
$container->setParameter('kernel.container_class', 'app');
3939
$container->setParameter('kernel.environment', 'prod');
40-
$container->setParameter('kernel.root_dir', 'foo');
40+
$container->setParameter('kernel.project_dir', 'foo');
4141
$adapter = new Definition();
4242
$adapter->setAbstract(true);
4343
$adapter->addTag('cache.pool');
@@ -58,7 +58,7 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
5858
$container = new ContainerBuilder();
5959
$container->setParameter('kernel.environment', 'prod');
6060
$container->setParameter('kernel.container_class', 'app');
61-
$container->setParameter('kernel.root_dir', 'foo');
61+
$container->setParameter('kernel.project_dir', 'foo');
6262

6363
$container->register('cache.adapter.array', ArrayAdapter::class)->addArgument(0);
6464

@@ -128,7 +128,7 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
128128
$container->setParameter('kernel.debug', false);
129129
$container->setParameter('kernel.container_class', 'app');
130130
$container->setParameter('kernel.environment', 'prod');
131-
$container->setParameter('kernel.root_dir', 'foo');
131+
$container->setParameter('kernel.project_dir', 'foo');
132132
$adapter = new Definition();
133133
$adapter->setAbstract(true);
134134
$adapter->addTag('cache.pool');

Tests/Functional/app/AppKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ public function __construct($varDir, $testCase, $rootConfig, $environment, $debu
4747

4848
public function registerBundles()
4949
{
50-
if (!file_exists($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
50+
if (!file_exists($filename = $this->getProjectDir().'/'.$this->testCase.'/bundles.php')) {
5151
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
5252
}
5353

5454
return include $filename;
5555
}
5656

57-
public function getRootDir()
57+
public function getProjectDir()
5858
{
5959
return __DIR__;
6060
}

Tests/Functional/app/config/framework.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
framework:
22
secret: test
3-
router: { resource: "%kernel.root_dir%/%kernel.test_case%/routing.yml" }
3+
router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml" }
44
validation: { enabled: true, enable_annotations: true }
55
csrf_protection: true
66
form: true

0 commit comments

Comments
 (0)