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

Skip to content

Commit efffda4

Browse files
committed
[HttpKernel] deprecated usage of getRootDir() and kernel.root_dir
1 parent 7cb823a commit efffda4

File tree

23 files changed

+86
-47
lines changed

23 files changed

+86
-47
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
365365
if ($container->hasParameter('cache.prefix.seed')) {
366366
$seed = '.'.$container->getParameterBag()->resolveValue($container->getParameter('cache.prefix.seed'));
367367
} else {
368-
$seed = '_'.$container->getParameter('kernel.root_dir');
368+
$seed = '_'.$container->getParameter('kernel.project_dir');
369369
}
370370
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment').'.'.$container->getParameter('kernel.debug');
371371
$namespace = 'sf_'.$this->getMappingResourceExtension().'_'.$objectManagerName.'_'.ContainerBuilder::hash($seed);

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ protected function createContainer(array $data = array())
272272
'kernel.debug' => false,
273273
'kernel.environment' => 'test',
274274
'kernel.name' => 'kernel',
275-
'kernel.root_dir' => __DIR__,
275+
'kernel.project_dir' => __DIR__,
276276
), $data)));
277277
}
278278
}

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

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

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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 <[email protected]>
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);

src/Symfony/Bundle/FrameworkBundle/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()

src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ 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;
3232
}
3333

3434
public function registerContainerConfiguration(LoaderInterface $loader)

src/Symfony/Bundle/FrameworkBundle/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.name', '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);

src/Symfony/Bundle/FrameworkBundle/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.name', '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.name', '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.name', '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');

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public function getName()
5757

5858
public function registerBundles()
5959
{
60-
if (!is_file($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
60+
if (!is_file($filename = $this->getProjectDir().'/'.$this->testCase.'/bundles.php')) {
6161
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
6262
}
6363

6464
return include $filename;
6565
}
6666

67-
public function getRootDir()
67+
public function getProjectDir()
6868
{
6969
return __DIR__;
7070
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.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

src/Symfony/Bundle/SecurityBundle/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
assets: ~
66
csrf_protection: true

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function process(ContainerBuilder $container)
5050
if ($container->hasParameter('cache.prefix.seed')) {
5151
$seed = '.'.$container->getParameterBag()->resolveValue($container->getParameter('cache.prefix.seed'));
5252
} else {
53-
$seed = '_'.$container->getParameter('kernel.root_dir');
53+
$seed = '_'.$container->getParameter('kernel.project_dir');
5454
}
5555
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');
5656

src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolClearerPassTest.php

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

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

src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testNamespaceArgumentIsReplaced()
3434
$container->setParameter('kernel.debug', false);
3535
$container->setParameter('kernel.name', 'app');
3636
$container->setParameter('kernel.environment', 'prod');
37-
$container->setParameter('kernel.root_dir', 'foo');
37+
$container->setParameter('kernel.project_dir', 'foo');
3838
$adapter = new Definition();
3939
$adapter->setAbstract(true);
4040
$adapter->addTag('cache.pool');
@@ -55,7 +55,7 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
5555
$container = new ContainerBuilder();
5656
$container->setParameter('kernel.environment', 'prod');
5757
$container->setParameter('kernel.name', 'app');
58-
$container->setParameter('kernel.root_dir', 'foo');
58+
$container->setParameter('kernel.project_dir', 'foo');
5959

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

@@ -125,7 +125,7 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
125125
$container->setParameter('kernel.debug', false);
126126
$container->setParameter('kernel.name', 'app');
127127
$container->setParameter('kernel.environment', 'prod');
128-
$container->setParameter('kernel.root_dir', 'foo');
128+
$container->setParameter('kernel.project_dir', 'foo');
129129
$adapter = new Definition();
130130
$adapter->setAbstract(true);
131131
$adapter->addTag('cache.pool');

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* deprecated `kernel.root_dir` and `Kernel::getRootDir()`
8+
49
4.1.0
510
-----
611

0 commit comments

Comments
 (0)