-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] add "kernel.mode" for build-time env, keep "kernel.environment" for the runtime env #37584
8000New 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
Conversation
…onment" for the runtime env
My app currently have a local and production environment. Im happy to rename one of them to make the terminology less confusing. |
@Nyholm sure: I started with symfony/recipes#795, which explains why we sometimes need to know the runtime env. In this other PR, I proposed to introduce the |
In past projects, I have seen code that accessed the Can you elaborate a bit on what you're trying to achieve with that new env variable? |
@derrabus |
Reusing |
Sure, so is |
@@ -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())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this effectively turns --mode
into a reserve option name. So there is a BC impact for that change
@@ -104,6 +104,10 @@ protected static function createKernel(array $options = []) | |||
|
|||
if (isset($options['environment'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we rename the option to mode
as well ?
@@ -38,7 +38,14 @@ | |||
</span> | |||
</div> | |||
|
|||
{% if 'n/a' is not same as(collector.env) %} | |||
{% if collector.mode is defined %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding a comment that this condition is a BC layer, so that it can be cleaned when WebProfilerBundle becomes incompatible with HttpKernel <5.2
@@ -116,7 +123,14 @@ | |||
<span class="label">Symfony version</span> | |||
</div> | |||
|
|||
{% if 'n/a' != collector.env %} | |||
{% if collector.mode is defined %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
protected $debu 8000 g; | ||
protected $booted = false; | ||
protected $startTime; | ||
protected $mode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why making it protected ? This makes any BC layer harder (as child classes can do what they want with it). As there is a getter for it, child classes can still read it.
{ | ||
$this->environment = $environment; | ||
$this->mode = $mode; | ||
$this->environment = $mode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an incomplete BC layer. As the properties are protected, it misses handling property writes done in child classes.
We've just moved away from |
…default:kernel.environment:APP_RUNTIME_ENV)%` parameter (nicolas-grekas) This PR was merged into the 5.x branch. Discussion ---------- [HttpKernel] add `kernel.runtime_environment` = `%env(default:kernel.environment:APP_RUNTIME_ENV)%` parameter | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Instead of #37584 This PR adds a new `kernel.runtime_environment` parameter, which creates a convention to use the `APP_RUNTIME_ENV` env var to define the name of the runtime environment where the app is deployed. When this env var is not set, the parameter defaults to `kernel.environment`. This is especially useful for defining the location of the vault for secrets: an app can be deployed in "prod" mode, but still not be deployed on the real prod deployment target. When this happens, one might not use real prod secrets but instead, use a vault with creds for staging. This parameter enables this use case. Commits ------- 6eb9d62 [HttpKernel] add `kernel.runtime_environment` = `%env(default:kernel.environment:APP_RUNTIME_ENV)%` parameter
This PR renames the "kernel environment" to use the "kernel mode" terminology.
The "mode" (prod/dev/test) is the name of the build-time environment.
A new parameter is introduced, named
%kernel.mode%
, which holds the same as what is currently named%kernel.environment%
.%kernel.environment%
is kept but now becomes a reference to an env var namedAPP_RUNTIME_ENV
by default (and which defaults to%kernel.mode%
when the env var is not set.)This creates a potential BC breaks for apps that read the value of
%kernel.environment%
at compile time. I don't know if that's a blocker or not. In Symfony itself, we always use$kernel->getEnvironment()
so that this is never an issue. The only place where we use%kernel.environment%
is in theframework.secrets
config tree and this one should stay as-is: we do want this to be runtime-configurable.Pending recipe update coming next.
#36652 to be updated accordingly also.