8000 [Dotenv] Make load() variadic · symfony/symfony@96081cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 96081cd

Browse files
committed
[Dotenv] Make load() variadic
1 parent 3bbb657 commit 96081cd

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ final class Dotenv
4545
* @throws FormatException when a file has a syntax error
4646
* @throws PathException when a file does not exist or is not readable
4747
*/
48-
public function load($path/*, ...$paths*/)
48+
public function load($path, ...$paths)
4949
{
50-
// func_get_args() to be replaced by a variadic argument for Symfony 4.0
51-
foreach (func_get_args() as $path) {
50+
array_unshift($paths, $path);
51+
52+
foreach ($paths as $path) {
5253
if (!is_readable($path) || is_dir($path)) {
5354
throw new PathException($path);
5455
}

src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ public function testLoadDirectory()
155155
$dotenv->load(__DIR__);
156156
}
157157

158+
public function testLoad()
159+
{
160+
@mkdir($tmpdir = sys_get_temp_dir().'/dotenv');
161+
162+
$path1 = tempnam($tmpdir, 'sf-');
163+
$path2 = tempnam($tmpdir, 'sf-');
164+
165+
file_put_contents($path1, 'FOO=BAR');
166+
file_put_contents($path2, 'BAR=BAZ');
167+
168+
(new DotEnv())->load($path1, $path2);
169+
170+
$this->assertSame('BAR', getenv('FOO'));
171+
$this->assertSame('BAZ', getenv('BAR'));
172+
173+
putenv('FOO');
174+
putenv('BAR');
175+
unlink($path1);
176+
unlink($path2);
177+
rmdir($tmpdir);
178+
}
179+
158180
public function testServerSuperglobalIsNotOverriden()
159181
{
160182
$originalValue = $_SERVER['argc'];

0 commit comments

Comments
 (0)
0