diff --git a/UPGRADE-5.3.md b/UPGRADE-5.3.md new file mode 100644 index 0000000000000..c7b1ef71bbde8 --- /dev/null +++ b/UPGRADE-5.3.md @@ -0,0 +1,9 @@ +UPGRADE FROM 5.2 to 5.3 +======================= + +HttpKernel +---------- + + * Deprecated the `Kernel::$environment` property, use `Kernel::$mode` instead + * Deprecated the `KernelInterface::getEnvironment()` method, use `KernelInterface::getMode()` instead + * Deprecated the `ConfigDataCollector::getEnv()` method, use `ConfigDataCollector::getMode()` instead diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index 69db8ccddbb48..99b979ce92aa8 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -71,6 +71,9 @@ HttpKernel * Made `WarmableInterface::warmUp()` return a list of classes or files to preload on PHP 7.4+ * Removed support for `service:action` syntax to reference controllers. Use `serviceOrFqcn::method` instead. + * Removed the `Kernel::$environment` property, use `Kernel::$mode` instead + * Removed the `KernelInterface::getEnvironment()` method, use `KernelInterface::getMode()` instead + * Removed the `ConfigDataCollector::getEnv()` method, use `ConfigDataCollector::getMode()` instead Inflector --------- diff --git a/src/Symfony/Bridge/Twig/AppVariable.php b/src/Symfony/Bridge/Twig/AppVariable.php index f5a6494ed29bc..89408bf48ecbe 100644 --- a/src/Symfony/Bridge/Twig/AppVariable.php +++ b/src/Symfony/Bridge/Twig/AppVariable.php @@ -27,6 +27,7 @@ class AppVariable private $tokenStorage; private $requestStack; private $environment; + private $mode; private $debug; public function setTokenStorage(TokenStorageInterface $tokenStorage) @@ -44,6 +45,11 @@ public function setEnvironment(string $environment) $this->environment = $environment; } + public function setMode(string $mode): void + { + $this->mode = $mode; + } + public function setDebug(bool $debug) { $this->debug = $debug; @@ -130,6 +136,18 @@ public function getEnvironment() return $this->environment; } + /** + * Returns the current app mode name (e.g 'dev'). + */ + public function getMode(): string + { + if (null === $this->mode) { + throw new \RuntimeException('The "app.mode" variable is not available.'); + } + + return $this->mode; + } + /** * Returns the current app debug mode. * diff --git a/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php b/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php index 59539f278c05a..599fe32db7b4f 100644 --- a/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php +++ b/src/Symfony/Bridge/Twig/Tests/AppVariableTest.php @@ -45,6 +45,13 @@ public function testEnvironment() $this->assertEquals('dev', $this->appVariable->getEnvironment()); } + public function testMode() + { + $this->appVariable->setMode('dev'); + + $this->assertEquals('dev', $this->appVariable->getMode()); + } + /** * @runInSeparateProcess */ @@ -120,6 +127,12 @@ public function testEnvironmentNotSet() $this->appVariable->getEnvironment(); } + public function testModeNotSet() + { + $this->expectException('RuntimeException'); + $this->appVariable->getMode(); + } + public function testDebugNotSet() { $this->expectException('RuntimeException'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php index e39772edf4db1..ca6a10821162a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php @@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ['Kernel'], new TableSeparator(), ['Type', \get_class($kernel)], - ['Environment', $kernel->getEnvironment()], + ['Mode', $kernel->getMode()], ['Debug', $kernel->isDebug() ? 'true' : 'false'], ['Charset', $kernel->getCharset()], ['Cache directory', self::formatPath($kernel->getCacheDir(), $kernel->getProjectDir()).' ('.self::formatFileSize($kernel->getCacheDir()).')'], diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index 0dada3d7d172f..bef1f416c46e1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -60,11 +60,11 @@ protected function configure() ]) ->setDescription('Clears the cache') ->setHelp(<<<'EOF' -The %command.name% command clears the application cache for a given environment +The %command.name% command clears the application cache for a given mode and debug mode: - php %command.full_name% --env=dev - php %command.full_name% --env=prod --no-debug + php %command.full_name% --mode=dev + php %command.full_name% --mode=prod --no-debug EOF ) ; @@ -94,9 +94,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realCacheDir)); } - $io->comment(sprintf('Clearing the cache for the %s environment with debug %s', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); + $io->comment(sprintf('Clearing the cache for the %s mode with debug %s', $kernel->getMode(), var_export($kernel->isDebug(), true))); $this->cacheClearer->clear($realBuildDir); - $this->cacheClearer->clear($realCacheDir); // The current event dispatcher is stale, let's not use it anymore $this->getApplication()->setDispatcher(new EventDispatcher()); @@ -199,7 +198,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->comment('Finished'); } - $io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); + $io->success(sprintf('Cache for the "%s" mode (debug=%s) was successfully cleared.', $kernel->getMode(), var_export($kernel->isDebug(), true))); return 0; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php index 8feb2dd9c51b2..fb6d9499f65df 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php @@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io = new SymfonyStyle($input, $output); $kernel = $this->getApplication()->getKernel(); - $io->comment(sprintf('Warming up the cache for the %s environment with debug %s', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); + $io->comment(sprintf('Warming up the cache for the %s mode with debug %s', $kernel->getMode(), var_export($kernel->isDebug(), true))); if (!$input->getOption('no-optional-warmers')) { $this->cacheWarmer->enableOptionalWarmers(); @@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int Preloader::append($preloadFile, $preload); } - $io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully warmed.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); + $io->success(sprintf('Cache for the "%s" mode (debug=%s) was successfully warmed.', $kernel->getMode(), var_export($kernel->isDebug(), true))); return 0; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 7c330dbdf4f85..fd0b48c506ed5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -85,7 +85,7 @@ protected function configure() Display a specific environment variable by specifying its name with the --env-var option: - php %command.full_name% --env-var=APP_ENV + php %command.full_name% --env-var=APP_MODE Use the --tags option to display tagged public services grouped by tag: diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index d1a4682b50ab5..ae448436417bb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -40,7 +40,8 @@ public function __construct(KernelInterface $kernel) parent::__construct('Symfony', Kernel::VERSION); $inputDefinition = $this->getDefinition(); - $inputDefinition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment())); + $inputDefinition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getMode())); + $inputDefinition->addOption(new InputOption('--mode', null, InputOption::VALUE_REQUIRED, 'The Mode name.', $kernel->getMode())); $inputDefinition->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')); } @@ -147,7 +148,7 @@ public function all($namespace = null) */ public function getLongVersion() { - return parent::getLongVersion().sprintf(' (env: %s, debug: %s)', $this->kernel->getEnvironment(), $this->kernel->isDebug() ? 'true' : 'false'); + return parent::getLongVersion().sprintf(' (mode: %s, debug: %s)', $this->kernel->getMode(), $this->kernel->isDebug() ? 'true' : 'false'); } public function add(Command $command) diff --git a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php index 7f3d35d803563..2bb29b07504d7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php @@ -69,7 +69,7 @@ trait MicroKernelTrait public function getCacheDir(): string { if (isset($_SERVER['APP_CACHE_DIR'])) { - return $_SERVER['APP_CACHE_DIR'].'/'.$this->environment; + return $_SERVER['APP_CACHE_DIR'].'/'.$this->mode; } return parent::getCacheDir(); @@ -90,7 +90,7 @@ public function registerBundles(): iterable { $contents = require $this->getProjectDir().'/config/bundles.php'; foreach ($contents as $class => $envs) { - if ($envs[$this->environment] ?? $envs['all'] ?? false) { + if ($envs[$this->mode] ?? $envs['all'] ?? false) { yield new $class(); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php index 809a85dfdf284..f0acc137a4868 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php @@ -104,6 +104,10 @@ protected static function createKernel(array $options = []) if (isset($options['environment'])) { $env = $options['environment']; + } elseif (isset($_ENV['APP_MODE'])) { + $env = $_ENV['APP_MODE']; + } elseif (isset($_SERVER['APP_MODE'])) { + $env = $_SERVER['APP_MODE']; } elseif (isset($_ENV['APP_ENV'])) { $env = $_ENV['APP_ENV']; } elseif (isset($_SERVER['APP_ENV'])) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php index 42981c41484f1..6deaf7b706afc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php @@ -18,7 +18,6 @@ use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer; -use Symfony\Component\HttpKernel\KernelInterface; class CachePoolDeleteCommandTest extends TestCase { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePruneCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePruneCommandTest.php index 4df5fc024c235..497bea3c07852 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePruneCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePruneCommandTest.php @@ -18,7 +18,6 @@ use Symfony\Component\Cache\PruneableInterface; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; -use Symfony\Component\HttpKernel\KernelInterface; class CachePruneCommandTest extends TestCase { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/KernelInterface.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/KernelInterface.php new file mode 100644 index 0000000000000..afdb0a0703155 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/KernelInterface.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Command; + +use Symfony\Component\HttpKernel\KernelInterface as BaseKernelInterface; + +interface KernelInterface extends BaseKernelInterface +{ + public function getMode(): string; +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php index 2505d07881267..6801ef2271e38 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php @@ -16,7 +16,6 @@ use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php index 84e12759ce2fa..c82d5b9fdbd85 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php @@ -92,7 +92,7 @@ public function testDebugCustomDirectory() { $this->fs->mkdir($this->translationDir.'/customDir/translations'); $this->fs->mkdir($this->translationDir.'/customDir/templates'); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); $kernel->expects($this->once()) ->method('getBundle') ->with($this->equalTo($this->translationDir.'/customDir')) @@ -111,7 +111,7 @@ public function testDebugCustomDirectory() public function testDebugInvalidDirectory() { $this->expectException('InvalidArgumentException'); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); $kernel->expects($this->once()) ->method('getBundle') ->with($this->equalTo('dir')) @@ -170,7 +170,7 @@ function ($path, $catalogue) use ($loadedMessages) { ['foo', $this->getBundle($this->translationDir)], ['test', $this->getBundle('test')], ]; - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); $kernel ->expects($this->any()) ->method('getBundle') diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php index 0a86166fc7314..f6dc1366e3573 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php @@ -17,7 +17,6 @@ use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel; class TranslationUpdateCommandTest extends TestCase { @@ -143,7 +142,7 @@ protected function tearDown(): void /** * @return CommandTester */ - private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = []) + private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = []) { $translator = $this->getMockBuilder('Symfony\Component\Translation\Translator') ->disableOriginalConstructor() @@ -189,7 +188,7 @@ function ($path, $catalogue) use ($loadedMessages) { ['foo', $this->getBundle($this->translationDir)], ['test', $this->getBundle('test')], ]; - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); $kernel ->expects($this->any()) ->method('getBundle') diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/XliffLintCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/XliffLintCommandTest.php index 7d6783d9352c0..8223a7ecb217d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/XliffLintCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/XliffLintCommandTest.php @@ -19,7 +19,6 @@ use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\HttpKernel\KernelInterface; /** * Tests the part of the XliffLintCommand managed by the FrameworkBundle. The diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/YamlLintCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/YamlLintCommandTest.php index af81f335e3cdb..e18fbf5de8ee5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/YamlLintCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/YamlLintCommandTest.php @@ -19,7 +19,6 @@ use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\HttpKernel\KernelInterface; /** * Tests the YamlLintCommand. diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php index ca18462634fb4..0e1eaf135e1b5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php @@ -13,6 +13,7 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber; +use Symfony\Bundle\FrameworkBundle\Tests\Command\KernelInterface; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Event\ConsoleErrorEvent; @@ -24,7 +25,6 @@ use Symfony\Component\Console\Tester\ApplicationTester; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\HttpKernel\KernelInterface; class ApplicationTest extends TestCase { @@ -264,7 +264,7 @@ private function getKernel(array $bundles, $useDispatcher = false) ->willReturnOnConsecutiveCalls([], []) ; - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); $kernel->expects($this->once())->method('boot'); $kernel ->expects($this->any()) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 990aa19a13506..191acfff0d908 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1627,6 +1627,7 @@ protected function createContainer(array $data = []) 'kernel.project_dir' => __DIR__, 'kernel.debug' => false, 'kernel.environment' => 'test', + 'kernel.mode' => 'test', 'kernel.name' => 'kernel', 'kernel.container_class' => 'testContainer', 'container.build_hash' => 'Abc1234', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php index 7dbe15c6c9a5d..916c973f20655 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php @@ -64,7 +64,7 @@ public function getProjectDir(): string public function getCacheDir(): string { - return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment; + return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->mode; } public function getLogDir(): string @@ -84,12 +84,12 @@ protected function build(ContainerBuilder $container) public function __sleep(): array { - return ['varDir', 'testCase', 'rootConfig', 'environment', 'debug']; + return ['varDir', 'testCase', 'rootConfig', 'mode', 'debug']; } public function __wakeup() { - $this->__construct($this->varDir, $this->testCase, $this->rootConfig, $this->environment, $this->debug); + $this->__construct($this->varDir, $this->testCase, $this->rootConfig, $this->mode, $this->debug); } protected function getKernelParameters(): array diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php index 72d23f03f30f7..c0008a2026b3e 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php @@ -22,12 +22,14 @@ */ class AppKernel extends Kernel { + protected $mode; + private $varDir; private $testCase; private $rootConfig; private $authenticatorManagerEnabled; - public function __construct($varDir, $testCase, $rootConfig, $environment, $debug, $authenticatorManagerEnabled = false) + public function __construct($varDir, $testCase, $rootConfig, $mode, $debug, $authenticatorManagerEnabled = false) { if (!is_dir(__DIR__.'/'.$testCase)) { throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase)); @@ -42,7 +44,8 @@ public function __construct($varDir, $testCase, $rootConfig, $environment, $debu $this->rootConfig = $rootConfig; $this->authenticatorManagerEnabled = $authenticatorManagerEnabled; - parent::__construct($environment, $debug); + $this->mode = $mode; + parent::__construct($mode, $debug); } /** @@ -69,7 +72,7 @@ public function getProjectDir(): string public function getCacheDir(): string { - return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment; + return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->mode; } public function getLogDir(): string @@ -92,7 +95,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) public function serialize() { - return serialize([$this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()]); + return serialize([$this->varDir, $this->testCase, $this->rootConfig, $this->mode, $this->isDebug()]); } public function unserialize($str) diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index be47f246de147..a1c4facb4a23d 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -4,6 +4,8 @@ CHANGELOG 5.2.0 ----- + * the `app.env` variable is now runtime-dependent when the `APP_RUNTIME_ENV` env var is defined + * added the `app.mode` variable: it's the build-time equivalent of `app.env` * deprecated the public `twig` service to private 5.0.0 diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.php b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.php index a7124a30c20aa..d8abc696fe7c7 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.php +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.php @@ -70,6 +70,7 @@ ->set('twig.app_variable', AppVariable::class) ->call('setEnvironment', [param('kernel.environment')]) + ->call('setMode', [param('kernel.mode')]) ->call('setDebug', [param('kernel.debug')]) ->call('setTokenStorage', [service('security.token_storage')->ignoreOnInvalid()]) ->call('setRequestStack', [service('request_stack')->ignoreOnInvalid()]) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 12eaa4ba4c41b..27e6a55691f71 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -246,6 +246,7 @@ public function testRuntimeLoader() $container->registerExtension(new TwigExtension()); $container->loadFromExtension('twig'); $container->setParameter('kernel.environment', 'test'); + $container->setParameter('kernel.mode', 'test'); $container->setParameter('debug.file_link_format', 'test'); $container->setParameter('foo', 'FooClass'); $container->register('http_kernel', 'FooClass'); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php index bfdf9418a765a..55fd8cde8de2f 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php @@ -69,7 +69,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) public function getCacheDir(): string { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel/cache/'.$this->environment; + return sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel/cache/'.$this->mode; } public function getLogDir(): string diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php index b571d1cc76094..df0e9813c7d6b 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/NoTemplatingEntryTest.php @@ -77,7 +77,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) public function getCacheDir(): string { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/cache/'.$this->environment; + return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/cache/'.$this->mode; } public function getLogDir(): string diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 0297efaeb8f47..1aecce77cbe73 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -20,7 +20,7 @@ "symfony/config": "^4.4|^5.0", "symfony/twig-bridge": "^5.0", "symfony/http-foundation": "^4.4|^5.0", - "symfony/http-kernel": "^5.0", + "symfony/http-kernel": "^5.2", "symfony/polyfill-ctype": "~1.8", "twig/twig": "^2.10|^3.0" }, diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig index 4e4a59d1b3ce4..56746f3678fae 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig @@ -38,7 +38,14 @@ - {% if 'n/a' is not same as(collector.env) %} + {% if collector.mode is defined %} + {% if 'n/a' is not same as(collector.mode) %} +
+ Mode + {{ collector.mode }} +
+ {% endif %} + {% elseif 'n/a' is not same as(collector.env) %}
Environment {{ collector.env }} @@ -116,7 +123,14 @@ Symfony version
- {% if 'n/a' != collector.env %} + {% if collector.mode is defined %} + {% if 'n/a' is not same as(collector.mode) %} +
+ {{ collector.mode }} + Mode +
+ {% endif %} + {% elseif 'n/a' != collector.env %}
{{ collector.env }} Environment diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index a655e2d6f945a..30776b6745577 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -1,6 +1,16 @@ CHANGELOG ========= +5.3.0 +----- + + * made parameter `kernel.environment` runtime-dependent when the `APP_RUNTIME_ENV` env var is set + * added parameter `kernel.mode`: it's the build-time equivalent of `kernel.environment` + * deprecated the `Kernel::$environment` property, use `Kernel::$mode` instead + * deprecated the `KernelInterface::getEnvironment()` method, use `KernelInterface::getMode()` instead + * deprecated the `ConfigDataCollector::getEnv()` method, use `ConfigDataCollector::getMode()` instead + + 5.2.0 ----- diff --git a/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php index ba0a3eec6e0c8..a136d4f2e7546 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php @@ -46,7 +46,7 @@ public function collect(Request $request, Response $response, \Throwable $except 'token' => $response->headers->get('X-Debug-Token'), 'symfony_version' => Kernel::VERSION, 'symfony_state' => 'unknown', - 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a', + 'mode' => isset($this->kernel) ? $this->kernel->getMode() : 'n/a', 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a', 'php_version' => \PHP_VERSION, 'php_architecture' => \PHP_INT_SIZE * 8, @@ -207,14 +207,23 @@ public function getPhpTimezone() return $this->data['php_timezone']; } + public function getMode(): string + { + return $this->data['mode']; + } + /** * Gets the environment. * * @return string The environment + * + * @deprecated since Symfony 5.2, use getMode() instead. */ public function getEnv() { - return $this->data['env']; + trigger_deprecation('symfony/http-kernel', '5.2', 'The "%s()" method is deprecated, use getMode() instead.', __METHOD__); + + return $this->data['mode']; } /** diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index ad9a4b2d78a5b..c2c404f03b8d6 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -47,9 +47,9 @@ class_exists(ConfigCache::class); /** * The Kernel is the heart of the Symfony system. * - * It manages an environment made of bundles. + * It manages a mode made of bundles. * - * Environment names must always start with a letter and + * Mode names must always start with a letter and * they must only contain letters and numbers. * * @author Fabien Potencier @@ -62,10 +62,15 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl protected $bundles = []; protected $container; - protected $environment; protected $debug; protected $booted = false; protected $startTime; + protected $mode; + + /** + * @deprecated since Symfony 5.2, use $mode instead + */ + protected $environment; private $projectDir; private $warmupDir; @@ -84,9 +89,10 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; - public function __construct(string $environment, bool $debug) + public function __construct(string $mode, bool $debug) { - $this->environment = $environment; + $this->mode = $mode; + $this->environment = $mode; $this->debug = $debug; } @@ -257,10 +263,22 @@ public function locateResource(string $name) /** * {@inheritdoc} + * + * @deprecated since Symfony 5.2, use getMode() instead. */ public function getEnvironment() { - return $this->environment; + trigger_deprecation('symfony/http-kernel', '5.2', 'The "%s()" method is deprecated, use getMode() instead.', __METHOD__); + + return $this->mode; + } + + /** + * {@inheritdoc} + */ + public function getMode(): string + { + return $this->mode; } /** @@ -331,7 +349,7 @@ public function getStartTime() */ public function getCacheDir() { - return $this->getProjectDir().'/var/cache/'.$this->environment; + return $this->getProjectDir().'/var/cache/'.$this->mode; } /** @@ -405,10 +423,10 @@ protected function getContainerClass() { $class = static::class; $class = false !== strpos($class, "@anonymous\0") ? get_parent_class($class).str_replace('.', '_', ContainerBuilder::hash($class)) : $class; - $class = str_replace('\\', '_', $class).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container'; + $class = str_replace('\\', '_', $class).ucfirst($this->mode).($this->debug ? 'Debug' : '').'Container'; if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { - throw new \InvalidArgumentException(sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', $this->environment)); + throw new \InvalidArgumentException(sprintf('The mode "%s" contains invalid characters, it can only contain characters allowed in PHP class names.', $this->mode)); } return $class; @@ -605,7 +623,8 @@ protected function getKernelParameters() return [ 'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(), - 'kernel.environment' => $this->environment, + 'kernel.environment' => 'env(default:kernel.mode:APP_RUNTIME_ENV)', + 'kernel.mode' => $this->mode, 'kernel.debug' => $this->debug, 'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir, 'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(), @@ -854,11 +873,11 @@ public static function stripComments(string $source) */ public function __sleep() { - return ['environment', 'debug']; + return ['mode', 'debug']; } public function __wakeup() { - $this->__construct($this->environment, $this->debug); + $this->__construct($this->environment ?? $this->mode, $this->debug); } } diff --git a/src/Symfony/Component/HttpKernel/KernelInterface.php b/src/Symfony/Component/HttpKernel/KernelInterface.php index c1be3aff43ee0..a0932d1c3a5f3 100644 --- a/src/Symfony/Component/HttpKernel/KernelInterface.php +++ b/src/Symfony/Component/HttpKernel/KernelInterface.php @@ -23,6 +23,7 @@ * @method string getBuildDir() Returns the build directory - not implementing it is deprecated since Symfony 5.2. * This directory should be used to store build artifacts, and can be read-only at runtime. * Caches written at runtime should be stored in the "cache directory" ({@see KernelInterface::getCacheDir()}). + * @method string getMode() * * @author Fabien Potencier */ @@ -91,6 +92,8 @@ public function locateResource(string $name); * Gets the environment. * * @return string The current environment + * + * @deprecated since Symfony 5.2, use getMode() instead. */ public function getEnvironment(); diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/ConfigDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/ConfigDataCollectorTest.php index 308a20127acf2..d6c1f23cbaa7e 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/ConfigDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/ConfigDataCollectorTest.php @@ -27,7 +27,7 @@ public function testCollect() $c->setKernel($kernel); $c->collect(new Request(), new Response()); - $this->assertSame('test', $c->getEnv()); + $this->assertSame('test', $c->getMode()); $this->assertTrue($c->isDebug()); $this->assertSame('config', $c->getName()); $this->assertMatchesRegularExpression('~^'.preg_quote($c->getPhpVersion(), '~').'~', \PHP_VERSION); diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index beb4b9fe3fa66..f5bcc7f6c7707 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -40,11 +40,11 @@ protected function tearDown(): void public function testConstructor() { - $env = 'test_env'; + $mode = 'test_mode'; $debug = true; - $kernel = new KernelForTest($env, $debug); + $kernel = new KernelForTest($mode, $debug); - $this->assertEquals($env, $kernel->getEnvironment()); + $this->assertEquals($mode, $kernel->getMode()); $this->assertEquals($debug, $kernel->isDebug()); $this->assertFalse($kernel->isBooted()); $this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime()); @@ -52,13 +52,13 @@ public function testConstructor() public function testClone() { - $env = 'test_env'; + $mode = 'test_mode'; $debug = true; - $kernel = new KernelForTest($env, $debug); + $kernel = new KernelForTest($mode, $debug); $clone = clone $kernel; - $this->assertEquals($env, $clone->getEnvironment()); + $this->assertEquals($mode, $clone->getMode()); $this->assertEquals($debug, $clone->isDebug()); $this->assertFalse($clone->isBooted()); $this->assertLessThanOrEqual(microtime(true), $clone->getStartTime()); @@ -67,11 +67,11 @@ public function testClone() public function testClassNameValidityGetter() { $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessage('The environment "test.env" contains invalid characters, it can only contain characters allowed in PHP class names.'); - // We check the classname that will be generated by using a $env that + $this->expectExceptionMessage('The mode "test.mode" contains invalid characters, it can only contain characters allowed in PHP class names.'); + // We check the classname that will be generated by using a $mode that // contains invalid characters. - $env = 'test.env'; - $kernel = new KernelForTest($env, false, false); + $mode = 'test.mode'; + $kernel = new KernelForTest($mode, false, false); $kernel->boot(); } @@ -310,10 +310,10 @@ public function doStuff() public function testSerialize() { - $env = 'test_env'; + $mode = 'test_mode'; $debug = true; - $kernel = new KernelForTest($env, $debug); - $expected = "O:57:\"Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest\":2:{s:14:\"\0*\0environment\";s:8:\"test_env\";s:8:\"\0*\0debug\";b:1;}"; + $kernel = new KernelForTest($mode, $debug); + $expected = "O:57:\"Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest\":2:{s:7:\"\0*\0mode\";s:9:\"test_mode\";s:8:\"\0*\0debug\";b:1;}"; $this->assertEquals($expected, serialize($kernel)); } @@ -671,9 +671,9 @@ class CustomProjectDirKernel extends Kernel implements WarmableInterface private $buildContainer; private $httpKernel; - public function __construct(\Closure $buildContainer = null, HttpKernelInterface $httpKernel = null, $env = 'custom') + public function __construct(\Closure $buildContainer = null, HttpKernelInterface $httpKernel = null, $mode = 'custom') { - parent::__construct($env, true); + parent::__construct($mode, true); $this->buildContainer = $buildContainer; $this->httpKernel = $httpKernel;