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

Skip to content

Commit 6888c01

Browse files
[HttpKernel] add "kernel.mode" for build-time env, keep "kernel.environment" for the runtime env
1 parent ba4d57b commit 6888c01

File tree

27 files changed

+158
-53
lines changed

27 files changed

+158
-53
lines changed

UPGRADE-5.2.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ DependencyInjection
66

77
* Deprecated `Definition::setPrivate()` and `Alias::setPrivate()`, use `setPublic()` instead
88

9+
HttpKernel
10+
----------
11+
12+
* Deprecated the `Kernel::$environment` property, use `Kernel::$mode` instead
13+
* Deprecated the `KernelInterface::getEnvironment()` method, use `KernelInterface::getMode()` instead
14+
* Deprecated the `ConfigDataCollector::getEnv()` method, use `ConfigDataCollector::getMode()` instead
15+
916
Mime
1017
----
1118

UPGRADE-6.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ HttpKernel
6868

6969
* Made `WarmableInterface::warmUp()` return a list of classes or files to preload on PHP 7.4+
7070
* Removed support for `service:action` syntax to reference controllers. Use `serviceOrFqcn::method` instead.
71+
* Removed the `Kernel::$environment` property, use `Kernel::$mode` instead
72+
* Removed the `KernelInterface::getEnvironment()` method, use `KernelInterface::getMode()` instead
73+
* Removed the `ConfigDataCollector::getEnv()` method, use `ConfigDataCollector::getMode()` instead
7174

7275
Inflector
7376
---------

src/Symfony/Bridge/Twig/AppVariable.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class AppVariable
2727
private $tokenStorage;
2828
private $requestStack;
2929
private $environment;
30+
private $mode;
3031
private $debug;
3132

3233
public function setTokenStorage(TokenStorageInterface $tokenStorage)
@@ -44,6 +45,11 @@ public function setEnvironment(string $environment)
4445
$this->environment = $environment;
4546
}
4647

48+
public function setMode(string $mode): void
49+
{
50+
$this->mode = $mode;
51+
}
52+
4753
public function setDebug(bool $debug)
4854
{
4955
$this->debug = $debug;
@@ -130,6 +136,18 @@ public function getEnvironment()
130136
return $this->environment;
131137
}
132138

139+
/**
140+
* Returns the current app mode name (e.g 'dev').
141+
*/
142+
public function getMode(): string
143+
{
144+
if (null === $this->mode) {
145+
throw new \RuntimeException('The "app.mode" variable is not available.');
146+
}
147+
148+
return $this->mode;
149+
}
150+
133151
/**
134152
* Returns the current app debug mode.
135153
*

src/Symfony/Bridge/Twig/Tests/AppVariableTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public function testEnvironment()
4545
$this->assertEquals('dev', $this->appVariable->getEnvironment());
4646
}
4747

48+
public function testMode()
49+
{
50+
$this->appVariable->setMode('dev');
51+
52+
$this->assertEquals('dev', $this->appVariable->getMode());
53+
}
54+
4855
/**
4956
* @runInSeparateProcess
5057
*/
@@ -120,6 +127,12 @@ public function testEnvironmentNotSet()
120127
$this->appVariable->getEnvironment();
121128
}
122129

130+
public function testModeNotSet()
131+
{
132+
$this->expectException('RuntimeException');
133+
$this->appVariable->getMode();
134+
}
135+
123136
public function testDebugNotSet()
124137
{
125138
$this->expectException('RuntimeException');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7272
['<info>Kernel</>'],
7373
new TableSeparator(),
7474
['Type', \get_class($kernel)],
75-
['Environment', $kernel->getEnvironment()],
75+
['Mode', $kernel->getMode()],
7676
['Debug', $kernel->isDebug() ? 'true' : 'false'],
7777
['Charset', $kernel->getCharset()],
7878
['Cache directory', self::formatPath($kernel->getCacheDir(), $kernel->getProjectDir()).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'],

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ protected function configure()
6060
])
6161
->setDescription('Clears the cache')
6262
->setHelp(<<<'EOF'
63-
The <info>%command.name%</info> command clears the application cache for a given environment
63+
The <info>%command.name%</info> command clears the application cache for a given mode
6464
and debug mode:
6565
66-
<info>php %command.full_name% --env=dev</info>
67-
<info>php %command.full_name% --env=prod --no-debug</info>
66+
<info>php %command.full_name% --mode=dev</info>
67+
<info>php %command.full_name% --mode=prod --no-debug</info>
6868
EOF
6969
)
7070
;
@@ -89,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8989
throw new RuntimeException(sprintf('Unable to write in the "%s" directory.', $realCacheDir));
9090
}
9191

92-
$io->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
92+
$io->comment(sprintf('Clearing the cache for the <info>%s</info> mode with debug <info>%s</info>', $kernel->getMode(), var_export($kernel->isDebug(), true)));
9393
$this->cacheClearer->clear($realCacheDir);
9494

9595
// The current event dispatcher is stale, let's not use it anymore
@@ -179,7 +179,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
179179
$io->comment('Finished');
180180
}
181181

182-
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
182+
$io->success(sprintf('Cache for the "%s" mode (debug=%s) was successfully cleared.', $kernel->getMode(), var_export($kernel->isDebug(), true)));
183183

184184
return 0;
185185
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7272
$io = new SymfonyStyle($input, $output);
7373

7474
$kernel = $this->getApplication()->getKernel();
75-
$io->comment(sprintf('Warming up the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
75+
$io->comment(sprintf('Warming up the cache for the <info>%s</info> mode with debug <info>%s</info>', $kernel->getMode(), var_export($kernel->isDebug(), true)));
7676

7777
if (!$input->getOption('no-optional-warmers')) {
7878
$this->cacheWarmer->enableOptionalWarmers();
@@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8484
Preloader::append($preloadFile, $preload);
8585
}
8686

87-
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully warmed.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
87+
$io->success(sprintf('Cache for the "%s" mode (debug=%s) was successfully warmed.', $kernel->getMode(), var_export($kernel->isDebug(), true)));
8888

8989
return 0;
9090
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function configure()
8585
8686
Display a specific environment variable by specifying its name with the <info>--env-var</info> option:
8787
88-
<info>php %command.full_name% --env-var=APP_ENV</info>
88+
<info>php %command.full_name% --env-var=APP_MODE</info>
8989
9090
Use the --tags option to display tagged <comment>public</comment> services grouped by tag:
9191

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function __construct(KernelInterface $kernel)
4141

4242
$inputDefinition = $this->getDefinition();
4343
$inputDefinition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment()));
44+
$inputDefinition->addOption(new InputOption('--mode', null, InputOption::VALUE_REQUIRED, 'The Mode name.', $kernel->getMode()));
4445
$inputDefinition->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
4546
}
4647

@@ -147,7 +148,7 @@ public function all($namespace = null)
147148
*/
148149
public function getLongVersion()
149150
{
150-
return parent::getLongVersion().sprintf(' (env: <comment>%s</>, debug: <comment>%s</>)', $this->kernel->getEnvironment(), $this->kernel->isDebug() ? 'true' : 'false');
151+
return parent::getLongVersion().sprintf(' (mode: <comment>%s</>, debug: <comment>%s</>)', $this->kernel->getMode(), $this->kernel->isDebug() ? 'true' : 'false');
151152
}
152153

153154
public function add(Command $command)

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ trait MicroKernelTrait
6969
public function getCacheDir(): string
7070
{
7171
if (isset($_SERVER['APP_CACHE_DIR'])) {
72-
return $_SERVER['APP_CACHE_DIR'].'/'.$this->environment;
72+
return $_SERVER['APP_CACHE_DIR'].'/'.$this->mode;
7373
}
7474

7575
return parent::getCacheDir();
@@ -90,7 +90,7 @@ public function registerBundles(): iterable
9090
{
9191
$contents = require $this->getProjectDir().'/config/bundles.php';
9292
foreach ($contents as $class => $envs) {
93-
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
93+
if ($envs[$this->mode] ?? $envs['all'] ?? false) {
9494
yield new $class();
9595
}
9696
}

0 commit comments

Comments
 (0)