diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 2193854ad6..7abcd7fbdd 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -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 ------- diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php index b2891b4afa..e92afcd75c 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php @@ -365,7 +365,7 @@ abstract class AbstractDoctrineExtension extends Extension 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); diff --git a/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php b/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php index 5d4d1ee48c..417ac7a90a 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -272,7 +272,7 @@ class DoctrineExtensionTest extends TestCase 'kernel.debug' => false, 'kernel.environment' => 'test', 'kernel.container_class' => 'kernel', - 'kernel.root_dir' => __DIR__, + 'kernel.project_dir' => __DIR__, ), $data))); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php index 4128f57e13..a0d48b38f9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php @@ -74,7 +74,6 @@ EOT 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()).' ('.self::formatFileSize($kernel->getCacheDir()).')'), array('Log directory', self::formatPath($kernel->getLogDir(), $kernel->getProjectDir()).' ('.self::formatFileSize($kernel->getLogDir()).')'), new TableSeparator(), diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 6e2c1324ba..54f5f615e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -130,11 +130,11 @@ EOF $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 @@ EOF 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 @@ EOF 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()); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index cf79d78313..97e2d568dd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -120,11 +120,11 @@ EOF $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 @@ EOF 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 diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index a1cddf2808..563dba7673 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -16,22 +16,30 @@ use Symfony\Component\Templating\Helper\Helper; /** * @author Fabien Potencier + * + * @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 @@ class CodeHelper extends Helper 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('kernel.root_dir/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr); + $fileStr = sprintf('kernel.project_dir/%s', htmlspecialchars($this->projectDir, $flags, $this->charset), $fileStr); } $text = sprintf('%s at line %d', $fileStr, $line); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php index ef200d3a54..c2051ee152 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php @@ -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() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php index 213d75ecc6..1b171f7a4b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php @@ -26,9 +26,19 @@ class TestAppKernel extends Kernel ); } - 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) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php index 69aea35439..6467965da4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolClearerPassTest.php @@ -32,7 +32,7 @@ class CachePoolClearerPassTest extends TestCase $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); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php index d1f594f290..fe5e1469b0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/CachePoolPassTest.php @@ -37,7 +37,7 @@ class CachePoolPassTest extends TestCase $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 @@ class CachePoolPassTest extends TestCase $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 @@ class CachePoolPassTest extends TestCase $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'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php index e239bb5331..0af9934684 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php @@ -47,14 +47,14 @@ class AppKernel extends Kernel 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__; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml index 84c6e64e2a..040708e011 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml @@ -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 diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php index 00f9e371d0..4d3f7df20d 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php @@ -53,14 +53,14 @@ class AppKernel extends Kernel 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__; } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml index 955c41192e..ae33d776e4 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/FirewallEntryPoint/config.yml @@ -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 diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml index 2fa2338339..a6ee6533e8 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml @@ -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 diff --git a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php index 51d21639ec..4e6084528d 100644 --- a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php +++ b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php @@ -50,7 +50,7 @@ class CachePoolPass implements CompilerPassInterface 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'); diff --git a/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolClearerPassTest.php b/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolClearerPassTest.php index 9ce46f9d14..69e9acced9 100644 --- a/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolClearerPassTest.php +++ b/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolClearerPassTest.php @@ -29,7 +29,7 @@ class CachePoolClearerPassTest extends TestCase $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); diff --git a/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php b/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php index 5890c57e94..8bc4262c2f 100644 --- a/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php +++ b/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php @@ -34,7 +34,7 @@ class CachePoolPassTest extends TestCase $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 @@ class CachePoolPassTest extends TestCase $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 @@ class CachePoolPassTest extends TestCase $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'); diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 41590f7368..009f47c569 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -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 diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 9aea4c02b9..219ff05b29 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -54,6 +54,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl protected $bundles = array(); protected $container; + /** + * @deprecated since Symfony 4.2 + */ protected $rootDir; protected $environment; protected $debug; @@ -83,7 +86,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl { $this->environment = $environment; $this->debug = $debug; - $this->rootDir = $this->getRootDir(); + $this->rootDir = $this->getRootDir(false); $this->name = $this->getName(false); } @@ -281,7 +284,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl } if (null === $this->name) { - $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->rootDir)); + $this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', basename($this->getProjectDir())); if (ctype_digit($this->name[0])) { $this->name = '_'.$this->name; } @@ -308,9 +311,15 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl /** * {@inheritdoc} + * + * @deprecated since Symfony 4.2, use getProjectDir() instead */ - public function getRootDir() + 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()); @@ -370,7 +379,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ public function getCacheDir() { - return $this->rootDir.'/cache/'.$this->environment; + return $this->getProjectDir().'/var/cache/'.$this->environment; } /** @@ -378,7 +387,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ public function getLogDir() { - return $this->rootDir.'/logs'; + return $this->getProjectDir().'/var/log'; } /** @@ -582,6 +591,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl } return array( + /* + * @deprecated since Symfony 4.2, use kernel.project_dir instead + */ 'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir, 'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(), 'kernel.environment' => $this->environment, diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/123/Kernel123.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/123/Kernel123.php deleted file mode 100644 index d3a76684df..0000000000 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/123/Kernel123.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\Tests\Fixtures\_123; - -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\HttpKernel\Kernel; - -class Kernel123 extends Kernel -{ - public function registerBundles() - { - return array(); - } - - public function registerContainerConfiguration(LoaderInterface $loader) - { - } - - public function getCacheDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/kernel123/cache/'.$this->environment; - } - - public function getLogDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/kernel123/logs'; - } -} diff --git a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php index 9acee4cac5..9734594b6e 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fixtures/KernelForTest.php @@ -34,4 +34,14 @@ class KernelForTest extends Kernel { return $this->booted; } + + public function getCacheDir() + { + return $this->getProjectDir().'/Tests/Fixtures/cache.'.$this->environment; + } + + public function getLogDir() + { + return $this->getProjectDir().'/Tests/Fixtures/logs'; + } } diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 56d18e24d7..bc6ab05a53 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -33,7 +33,7 @@ class KernelTest extends TestCase public static function tearDownAfterClass() { $fs = new Filesystem(); - $fs->remove(__DIR__.'/Fixtures/cache'); + $fs->remove(__DIR__.'/Fixtures/var'); } public function testConstructor() @@ -67,15 +67,15 @@ class KernelTest extends TestCase public function testInitializeContainerClearsOldContainers() { $fs = new Filesystem(); - $legacyContainerDir = __DIR__.'/Fixtures/cache/custom/ContainerA123456'; + $legacyContainerDir = __DIR__.'/Fixtures/var/cache/custom/ContainerA123456'; $fs->mkdir($legacyContainerDir); touch($legacyContainerDir.'.legacy'); $kernel = new CustomProjectDirKernel(); $kernel->boot(); - $containerDir = __DIR__.'/Fixtures/cache/custom/'.substr(\get_class($kernel->getContainer()), 0, 16); - $this->assertTrue(unlink(__DIR__.'/Fixtures/cache/custom/FixturesSymfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta')); + $containerDir = __DIR__.'/Fixtures/var/cache/custom/'.substr(\get_class($kernel->getContainer()), 0, 16); + $this->assertTrue(unlink(__DIR__.'/Fixtures/var/cache/custom/Symfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta')); $this->assertFileExists($containerDir); $this->assertFileNotExists($containerDir.'.legacy'); @@ -295,6 +295,9 @@ EOF; $this->assertEquals($expected, $output); } + /** + * @group legacy + */ public function testGetRootDir() { $kernel = new KernelForTest('test', true); @@ -309,7 +312,7 @@ EOF; { $kernel = new KernelForTest('test', true); - $this->assertEquals('Fixtures', $kernel->getName()); + $this->assertEquals('HttpKernel', $kernel->getName()); } /** @@ -512,43 +515,32 @@ EOF; $this->assertTrue($kernel->getContainer()->getParameter('test_executed')); } - /** - * @group legacy - */ - public function testKernelRootDirNameStartingWithANumber() - { - $dir = __DIR__.'/Fixtures/123'; - require_once $dir.'/Kernel123.php'; - $kernel = new \Symfony\Component\HttpKernel\Tests\Fixtures\_123\Kernel123('dev', true); - $this->assertEquals('_123', $kernel->getName()); - } - public function testProjectDirExtension() { $kernel = new CustomProjectDirKernel(); $kernel->boot(); - $this->assertSame('foo', $kernel->getProjectDir()); - $this->assertSame('foo', $kernel->getContainer()->getParameter('kernel.project_dir')); + $this->assertSame(__DIR__.'/Fixtures', $kernel->getProjectDir()); + $this->assertSame(__DIR__.'/Fixtures', $kernel->getContainer()->getParameter('kernel.project_dir')); } public function testKernelReset() { - (new Filesystem())->remove(__DIR__.'/Fixtures/cache'); + (new Filesystem())->remove(__DIR__.'/Fixtures/var/cache'); $kernel = new CustomProjectDirKernel(); $kernel->boot(); $containerClass = \get_class($kernel->getContainer()); $containerFile = (new \ReflectionClass($kernel->getContainer()))->getFileName(); - unlink(__DIR__.'/Fixtures/cache/custom/FixturesSymfony_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/cache/custom/FixturesSymfony_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(); @@ -720,7 +712,6 @@ class CustomProjectDirKernel extends Kernel { parent::__construct($env, true); - $this->baseDir = 'foo'; $this->buildContainer = $buildContainer; $this->httpKernel = $httpKernel; } @@ -734,17 +725,7 @@ class CustomProjectDirKernel extends Kernel { } - protected function getContainerClass() - { - return $this->name.parent::getContainerClass(); - } - public function getProjectDir() - { - return $this->baseDir; - } - - public function getRootDir() { return __DIR__.'/Fixtures'; }