Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  Fix some redundant @return phpdoc
  [Dotenv][Runtime] Add $overrideExistingVars to bootEnv() and loadEnv() and dotenv_overload to SymfonyRuntime
  Add check and tests for public properties
  [BrowserKit][HttpClient][Routing] support building query strings with stringables
  • Loading branch information
xabbuh committed Oct 27, 2021
2 parents 44341b2 + 6f1c37c commit 7c200f1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

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

5.3.0
-----
Expand Down
4 changes: 3 additions & 1 deletion SymfonyRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class_exists(MissingDotenv::class, false) || class_exists(Dotenv::class) || clas
* - "prod_envs" to define the names of the production envs - defaults to ["prod"];
* - "test_envs" to define the names of the test envs - defaults to ["test"];
* - "use_putenv" to tell Dotenv to set env vars using putenv() (NOT RECOMMENDED.)
* - "dotenv_overload" to tell Dotenv to override existing vars
*
* When the "debug" / "env" options are not defined, they will fallback to the
* "APP_DEBUG" / "APP_ENV" environment variables, and to the "--env|-e" / "--no-debug"
Expand Down Expand Up @@ -84,6 +85,7 @@ class SymfonyRuntime extends GenericRuntime
* error_handler?: string|false,
* env_var_name?: string,
* debug_var_name?: string,
* dotenv_overload?: ?bool,
* } $options
*/
public function __construct(array $options = [])
Expand All @@ -102,7 +104,7 @@ public function __construct(array $options = [])
(new Dotenv($envKey, $debugKey))
->setProdEnvs((array) ($options['prod_envs'] ?? ['prod']))
->usePutenv($options['use_putenv'] ?? false)
->bootEnv($options['project_dir'].'/'.($options['dotenv_path'] ?? '.env'), 'dev', (array) ($options['test_envs'] ?? ['test']));
->bootEnv($options['project_dir'].'/'.($options['dotenv_path'] ?? '.env'), 'dev', (array) ($options['test_envs'] ?? ['test']), $options['dotenv_overload'] ?? false);
$options['debug'] ?? $options['debug'] = '1' === $_SERVER[$debugKey];
$options['disable_dotenv'] = true;
} else {
Expand Down
3 changes: 2 additions & 1 deletion Tests/phpt/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use Symfony\Component\Runtime\SymfonyRuntime;

$_SERVER['APP_RUNTIME_OPTIONS'] = [
$_SERVER['APP_RUNTIME_OPTIONS'] = $_SERVER['APP_RUNTIME_OPTIONS'] ?? [];
$_SERVER['APP_RUNTIME_OPTIONS'] += [
'project_dir' => __DIR__,
] + ($_SERVER['APP_RUNTIME_OPTIONS'] ?? []);

Expand Down
15 changes: 15 additions & 0 deletions Tests/phpt/dotenv_overload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$_SERVER['SOME_VAR'] = 'ccc';
$_SERVER['APP_RUNTIME_OPTIONS'] = [
'dotenv_overload' => true,
];

require __DIR__.'/autoload.php';

return function (Request $request, array $context) {
return new Response('OK Request '.$context['SOME_VAR']);
};
14 changes: 14 additions & 0 deletions Tests/phpt/dotenv_overload.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Test Dotenv overload
--SKIPIF--
<?php require dirname(__DIR__, 6).'/vendor/autoload.php'; if (4 > (new \ReflectionMethod(\Symfony\Component\Dotenv\Dotenv::class, 'bootEnv'))->getNumberOfParameters()) die('Skip because Dotenv version is too low');
--INI--
display_errors=1
--FILE--
<?php

require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/dotenv_overload.php';

?>
--EXPECTF--
OK Request foo_bar

0 comments on commit 7c200f1

Please sign in to comment.