8000 [HttpKernel] add "kernel.mode" for build-time env, keep "kernel.environment" for the runtime env by nicolas-grekas · Pull Request #37584 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] add "kernel.mode" for build-time env, keep "kernel.environment" for the runtime env #37584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPGRADE-5.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ DependencyInjection

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

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

Mime
----

Expand Down
3 changes: 3 additions & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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
---------
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Bridge/Twig/AppVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AppVariable
private $tokenStorage;
private $requestStack;
private $environment;
private $mode;
private $debug;

public function setTokenStorage(TokenStorageInterface $tokenStorage)
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Bridge/Twig/Tests/AppVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
['<info>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()).' (<comment>'.self::formatFileSize($kernel->getCacheDir()).'</>)'],
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php