Skip to content

Commit 7c200f1

Browse files
committed
Merge branch '5.4' into 6.0
* 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
2 parents 44341b2 + 6f1c37c commit 7c200f1

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* The component is not experimental anymore
88
* Add options "env_var_name" and "debug_var_name" to `GenericRuntime` and `SymfonyRuntime`
9+
* Add option "dotenv_overload" to `SymfonyRuntime`
910

1011
5.3.0
1112
-----

SymfonyRuntime.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class_exists(MissingDotenv::class, false) || class_exists(Dotenv::class) || clas
4040
* - "prod_envs" to define the names of the production envs - defaults to ["prod"];
4141
* - "test_envs" to define the names of the test envs - defaults to ["test"];
4242
* - "use_putenv" to tell Dotenv to set env vars using putenv() (NOT RECOMMENDED.)
43+
* - "dotenv_overload" to tell Dotenv to override existing vars
4344
*
4445
* When the "debug" / "env" options are not defined, they will fallback to the
4546
* "APP_DEBUG" / "APP_ENV" environment variables, and to the "--env|-e" / "--no-debug"
@@ -84,6 +85,7 @@ class SymfonyRuntime extends GenericRuntime
8485
* error_handler?: string|false,
8586
* env_var_name?: string,
8687
* debug_var_name?: string,
88+
* dotenv_overload?: ?bool,
8789
* } $options
8890
*/
8991
public function __construct(array $options = [])
@@ -102,7 +104,7 @@ public function __construct(array $options = [])
102104
(new Dotenv($envKey, $debugKey))
103105
->setProdEnvs((array) ($options['prod_envs'] ?? ['prod']))
104106
->usePutenv($options['use_putenv'] ?? false)
105-
->bootEnv($options['project_dir'].'/'.($options['dotenv_path'] ?? '.env'), 'dev', (array) ($options['test_envs'] ?? ['test']));
107+
->bootEnv($options['project_dir'].'/'.($options['dotenv_path'] ?? '.env'), 'dev', (array) ($options['test_envs'] ?? ['test']), $options['dotenv_overload'] ?? false);
106108
$options['debug'] ?? $options['debug'] = '1' === $_SERVER[$debugKey];
107109
$options['disable_dotenv'] = true;
108110
} else {

Tests/phpt/autoload.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
use Symfony\Component\Runtime\SymfonyRuntime;
44

5-
$_SERVER['APP_RUNTIME_OPTIONS'] = [
5+
$_SERVER['APP_RUNTIME_OPTIONS'] = $_SERVER['APP_RUNTIME_OPTIONS'] ?? [];
6+
$_SERVER['APP_RUNTIME_OPTIONS'] += [
67
'project_dir' => __DIR__,
78
] + ($_SERVER['APP_RUNTIME_OPTIONS'] ?? []);
89

Tests/phpt/dotenv_overload.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use Symfony\Component\HttpFoundation\Request;
4+
use Symfony\Component\HttpFoundation\Response;
5+
6+
$_SERVER['SOME_VAR'] = 'ccc';
7+
$_SERVER['APP_RUNTIME_OPTIONS'] = [
8+
'dotenv_overload' => true,
9+
];
10+
11+
require __DIR__.'/autoload.php';
12+
13+
return function (Request $request, array $context) {
14+
return new Response('OK Request '.$context['SOME_VAR']);
15+
};

Tests/phpt/dotenv_overload.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Test Dotenv overload
3+
--SKIPIF--
4+
<?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');
5+
--INI--
6+
display_errors=1
7+
--FILE--
8+
<?php
9+
10+
require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/dotenv_overload.php';
11+
12+
?>
13+
--EXPECTF--
14+
OK Request foo_bar

0 commit comments

Comments
 (0)