Skip to content

Commit 6499295

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: (30 commits) [HttpKernel] Add support for configuring log level, and status code by exception class Add return types to HttpCache createSurrogate and createStore methods [Serializer] Fix denormalizing of array with empty body Fix framework configuration when messenger uses without console [Security] Remove annoying deprecation in `UsageTrackingTokenStorage` [Mailer] Improve error message when STARTTLS fails [Security] Add alias for FirewallMapInterface to @security.firewall.map Bump Symfony version to 5.3.10 Update VERSION for 5.3.9 Fix CHANGELOG Update CHANGELOG for 5.3.9 Bump Symfony version to 4.4.33 Update VERSION for 4.4.32 Fix CHANGELOG Update CHANGELOG for 4.4.32 [Workflow] Remove dead code in XML schemas [Runtime] Fix test for env var names Bump Symfony version to 5.3.9 Update VERSION for 5.3.8 Update CHANGELOG for 5.3.8 ...
2 parents 00bce73 + 56b3b0c commit 6499295

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CHANGELOG
55
---
66

77
* The component is not experimental anymore
8-
* Add options "env_var_names" to `GenericRuntime` and `SymfonyRuntime`
8+
* Add options "env_var_name" and "debug_var_name" to `GenericRuntime` and `SymfonyRuntime`
99

1010
5.3.0
1111
-----

GenericRuntime.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class_exists(ClosureResolver::class);
2727
* to the "APP_DEBUG" environment variable;
2828
* - "runtimes" maps types to a GenericRuntime implementation
2929
* that knows how to deal with each of them;
30-
* - "error_handler" defines the class to use to handle PHP errors.
30+
* - "error_handler" defines the class to use to handle PHP errors;
31+
* - "env_var_name" and "debug_var_name" define the name of the env
32+
* vars that hold the Symfony env and the debug flag respectively.
3133
*
3234
* The app-callable can declare arguments among either:
3335
* - "array $context" to get a local array similar to $_SERVER;
@@ -51,13 +53,14 @@ class GenericRuntime implements RuntimeInterface
5153
* debug?: ?bool,
5254
* runtimes?: ?array,
5355
* error_handler?: string|false,
54-
* env_var_names?: ?array,
56+
* env_var_name?: string,
57+
* debug_var_name?: string,
5558
* } $options
5659
*/
5760
public function __construct(array $options = [])
5861
{
59-
$options['env_var_names']['env_key'] ?? $options['env_var_names']['env_key'] = 'APP_ENV';
60-
$debugKey = $options['env_var_names']['debug_key'] ?? $options['env_var_names']['debug_key'] = 'APP_DEBUG';
62+
$options['env_var_name'] ?? $options['env_var_name'] = 'APP_ENV';
63+
$debugKey = $options['debug_var_name'] ?? $options['debug_var_name'] = 'APP_DEBUG';
6164

6265
$debug = $options['debug'] ?? $_SERVER[$debugKey] ?? $_ENV[$debugKey] ?? true;
6366

@@ -107,7 +110,7 @@ public function getResolver(callable $callable, \ReflectionFunction $reflector =
107110
return $arguments;
108111
};
109112

110-
if ($_SERVER[$this->options['env_var_names']['debug_key']]) {
113+
if ($_SERVER[$this->options['debug_var_name']]) {
111114
return new DebugClosureResolver($callable, $arguments);
112115
}
113116

@@ -139,7 +142,7 @@ public function getRunner(?object $application): RunnerInterface
139142
$application = \Closure::fromCallable($application);
140143
}
141144

142-
if ($_SERVER[$this->options['env_var_names']['debug_key']] && ($r = new \ReflectionFunction($application)) && $r->getNumberOfRequiredParameters()) {
145+
if ($_SERVER[$this->options['debug_var_name']] && ($r = new \ReflectionFunction($application)) && $r->getNumberOfRequiredParameters()) {
143146
throw new \ArgumentCountError(sprintf('Zero argument should be required by the runner callable, but at least one is in "%s" on line "%d.', $r->getFileName(), $r->getStartLine()));
144147
}
145148

SymfonyRuntime.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ class SymfonyRuntime extends GenericRuntime
8282
* use_putenv?: ?bool,
8383
* runtimes?: ?array,
8484
* error_handler?: string|false,
85-
* env_var_names?: ?array,
85+
* env_var_name?: string,
86+
* debug_var_name?: string,
8687
* } $options
8788
*/
8889
public function __construct(array $options = [])
8990
{
90-
$envKey = $options['env_var_names']['env_key'] ?? $options['env_var_names']['env_key'] = 'APP_ENV';
91-
$debugKey = $options['env_var_names']['debug_key'] ?? $options['env_var_names']['debug_key'] = 'APP_DEBUG';
91+
$envKey = $options['env_var_name'] ?? $options['env_var_name'] = 'APP_ENV';
92+
$debugKey = $options['debug_var_name'] ?? $options['debug_var_name'] = 'APP_DEBUG';
9293

9394
if (isset($options['env'])) {
9495
$_SERVER[$envKey] = $options['env'];
@@ -144,7 +145,7 @@ public function getRunner(?object $application): RunnerInterface
144145
}
145146

146147
set_time_limit(0);
147-
$defaultEnv = !isset($this->options['env']) ? ($_SERVER[$this->options['env_var_names']['env_key']] ?? 'dev') : null;
148+
$defaultEnv = !isset($this->options['env']) ? ($_SERVER[$this->options['env_var_name']] ?? 'dev') : null;
148149
$output = $this->output ?? $this->output = new ConsoleOutput();
149150

150151
return new ConsoleApplicationRunner($application, $defaultEnv, $this->getInput(), $output);
@@ -209,11 +210,11 @@ private function getInput(): ArgvInput
209210
}
210211

211212
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
212-
putenv($this->options['env_var_names']['env_key'].'='.$_SERVER[$this->options['env_var_names']['env_key']] = $_ENV[$this->options['env_var_names']['env_key']] = $env);
213+
putenv($this->options['env_var_name'].'='.$_SERVER[$this->options['env_var_name']] = $_ENV[$this->options['env_var_name']] = $env);
213214
}
214215

215216
if ($input->hasParameterOption('--no-debug', true)) {
216-
putenv($this->options['env_var_names']['debug_key'].'='.$_SERVER[$this->options['env_var_names']['debug_key']] = $_ENV[$this->options['env_var_names']['debug_key']] = '0');
217+
putenv($this->options['debug_var_name'].'='.$_SERVER[$this->options['debug_var_name']] = $_ENV[$this->options['debug_var_name']] = '0');
217218
}
218219

219220
return $this->input = $input;

Tests/phpt/runtime-options.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

33
$_SERVER['APP_RUNTIME_OPTIONS'] = [
4-
'env_var_names' => [
5-
'env_key' => 'ENV_MODE',
6-
'debug_key' => 'DEBUG_MODE',
7-
],
4+
'env_var_name' => 'ENV_MODE',
5+
'debug_var_name' => 'DEBUG_MODE',
86
];
97
require __DIR__.'/autoload.php';
108

119
return function (array $context): void {
12-
echo 'Env mode ', $context['ENV_MODE'], ', debug mode ', $context['DEBUG_MODE'];
10+
if (isset($context['APP_ENV']) || isset($context['APP_DEBUG'])) {
11+
echo 'An error occurred on the variable name options.';
12+
} else {
13+
echo 'Env mode ', $context['ENV_MODE'], ', debug mode ', $context['DEBUG_MODE'];
14+
}
1315
};

0 commit comments

Comments
 (0)