Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Runtime] tweak config for env var names#43201

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:5.4fromnicolas-grekas:r-env-names
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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
2 changes: 1 addition & 1 deletionsrc/Symfony/Component/Runtime/CHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ CHANGELOG
---

* The component is not experimental anymore
* Add options "env_var_names" to `GenericRuntime` and `SymfonyRuntime`
* Add options "env_var_name" and "debug_var_name" to `GenericRuntime` and `SymfonyRuntime`

5.3.0
-----
Expand Down
15 changes: 9 additions & 6 deletionssrc/Symfony/Component/Runtime/GenericRuntime.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,7 +27,9 @@ class_exists(ClosureResolver::class);
* to the "APP_DEBUG" environment variable;
* - "runtimes" maps types to a GenericRuntime implementation
* that knows how to deal with each of them;
* - "error_handler" defines the class to use to handle PHP errors.
* - "error_handler" defines the class to use to handle PHP errors;
* - "env_var_name" and "debug_var_name" define the name of the env
* vars that hold the Symfony env and the debug flag respectively.
*
* The app-callable can declare arguments among either:
* - "array $context" to get a local array similar to $_SERVER;
Expand All@@ -51,13 +53,14 @@ class GenericRuntime implements RuntimeInterface
* debug?: ?bool,
* runtimes?: ?array,
* error_handler?: string|false,
* env_var_names?: ?array,
* env_var_name?: string,
* debug_var_name?: string,
* } $options
*/
public function __construct(array $options = [])
{
$options['env_var_names']['env_key'] ?? $options['env_var_names']['env_key'] = 'APP_ENV';
$debugKey = $options['env_var_names']['debug_key'] ?? $options['env_var_names']['debug_key'] = 'APP_DEBUG';
$options['env_var_name'] ?? $options['env_var_name'] = 'APP_ENV';
$debugKey = $options['debug_var_name'] ?? $options['debug_var_name'] = 'APP_DEBUG';

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

Expand DownExpand Up@@ -107,7 +110,7 @@ public function getResolver(callable $callable, \ReflectionFunction $reflector =
return $arguments;
};

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

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

if ($_SERVER[$this->options['env_var_names']['debug_key']] && ($r = new \ReflectionFunction($application)) && $r->getNumberOfRequiredParameters()) {
if ($_SERVER[$this->options['debug_var_name']] && ($r = new \ReflectionFunction($application)) && $r->getNumberOfRequiredParameters()) {
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()));
}

Expand Down
13 changes: 7 additions & 6 deletionssrc/Symfony/Component/Runtime/SymfonyRuntime.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,13 +82,14 @@ class SymfonyRuntime extends GenericRuntime
* use_putenv?: ?bool,
* runtimes?: ?array,
* error_handler?: string|false,
* env_var_names?: ?array,
* env_var_name?: string,
* debug_var_name?: string,
* } $options
*/
public function __construct(array $options = [])
{
$envKey = $options['env_var_names']['env_key'] ?? $options['env_var_names']['env_key'] = 'APP_ENV';
$debugKey = $options['env_var_names']['debug_key'] ?? $options['env_var_names']['debug_key'] = 'APP_DEBUG';
$envKey = $options['env_var_name'] ?? $options['env_var_name'] = 'APP_ENV';
$debugKey = $options['debug_var_name'] ?? $options['debug_var_name'] = 'APP_DEBUG';

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

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

return new ConsoleApplicationRunner($application, $defaultEnv, $this->getInput(), $output);
Expand DownExpand Up@@ -212,11 +213,11 @@ private function getInput(): ArgvInput
}

if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
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);
putenv($this->options['env_var_name'].'='.$_SERVER[$this->options['env_var_name']] = $_ENV[$this->options['env_var_name']] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
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');
putenv($this->options['debug_var_name'].'='.$_SERVER[$this->options['debug_var_name']] = $_ENV[$this->options['debug_var_name']] = '0');
}

return $this->input = $input;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp