Skip to content

Commit ff3461f

Browse files
committed
chore: reorder where functions are defined
1 parent b07b572 commit ff3461f

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

src/josegonzalez/Dotenv/Loader.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class Loader
2323

2424
protected $skip = array(
2525
'define' => false,
26+
'putenv' => false,
2627
'toEnv' => false,
2728
'toServer' => false,
28-
'putenv' => false
2929
);
3030

3131
public function __construct($filepaths = null)
@@ -66,9 +66,9 @@ public static function load($options = null)
6666
'prefix',
6767
'expect',
6868
'define',
69+
'putenv',
6970
'toEnv',
7071
'toServer',
71-
'putenv',
7272
);
7373
foreach ($methods as $method) {
7474
if (array_key_exists($method, $options)) {
@@ -252,45 +252,45 @@ public function define()
252252
return $this;
253253
}
254254

255-
public function toEnv($overwrite = false)
255+
public function putenv($overwrite = false)
256256
{
257-
$this->requireParse('toEnv');
257+
$this->requireParse('putenv');
258258
foreach ($this->environment as $key => $value) {
259259
$prefixedKey = $this->prefixed($key);
260-
if (isset($_ENV[$prefixedKey]) && !$overwrite) {
261-
if ($this->skip['toEnv']) {
260+
if (getenv($prefixedKey) && !$overwrite) {
261+
if ($this->skip['putenv']) {
262262
continue;
263263
}
264264

265265
return $this->raise(
266266
'LogicException',
267-
sprintf('Key "%s" has already been defined in $_ENV', $prefixedKey)
267+
sprintf('Key "%s" has already been defined in getenv()', $prefixedKey)
268268
);
269269
}
270270

271-
$_ENV[$prefixedKey] = $value;
271+
putenv($prefixedKey . '=' . $value);
272272
}
273273

274274
return $this;
275275
}
276276

277-
public function putenv($overwrite = false)
277+
public function toEnv($overwrite = false)
278278
{
279-
$this->requireParse('putenv');
279+
$this->requireParse('toEnv');
280280
foreach ($this->environment as $key => $value) {
281281
$prefixedKey = $this->prefixed($key);
282-
if (getenv($prefixedKey) && !$overwrite) {
283-
if ($this->skip['putenv']) {
282+
if (isset($_ENV[$prefixedKey]) && !$overwrite) {
283+
if ($this->skip['toEnv']) {
284284
continue;
285285
}
286286

287287
return $this->raise(
288288
'LogicException',
289-
sprintf('Key "%s" has already been defined in getenv()', $prefixedKey)
289+
sprintf('Key "%s" has already been defined in $_ENV', $prefixedKey)
290290
);
291291
}
292292

293-
putenv($prefixedKey . '=' . $value);
293+
$_ENV[$prefixedKey] = $value;
294294
}
295295

296296
return $this;

tests/josegonzalez/Dotenv/LoaderTest.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -580,48 +580,6 @@ public function testDefineException()
580580
$this->Loader->define();
581581
}
582582

583-
/**
584-
* @covers \josegonzalez\Dotenv\Loader::toEnv
585-
*/
586-
public function testToEnv()
587-
{
588-
$this->Loader->parse();
589-
$this->Loader->toEnv(false);
590-
591-
$this->assertEquals('bar', $_ENV['FOO']);
592-
$this->assertEquals('baz', $_ENV['BAR']);
593-
$this->assertEquals('with spaces', $_ENV['SPACED']);
594-
$this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']);
595-
}
596-
597-
/**
598-
* @covers \josegonzalez\Dotenv\Loader::toEnv
599-
*/
600-
public function testToEnvSkip()
601-
{
602-
$this->Loader->parse();
603-
$this->Loader->skipExisting('toEnv');
604-
$this->Loader->toEnv(false);
605-
$this->Loader->toEnv(false);
606-
607-
$this->assertEquals('bar', $_ENV['FOO']);
608-
$this->assertEquals('baz', $_ENV['BAR']);
609-
$this->assertEquals('with spaces', $_ENV['SPACED']);
610-
$this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']);
611-
}
612-
613-
/**
614-
* @covers \josegonzalez\Dotenv\Loader::toEnv
615-
* @expectedException LogicException
616-
* @expectedExceptionMessage Key "FOO" has already been defined in $_ENV
617-
*/
618-
public function testToEnvException()
619-
{
620-
$this->Loader->parse();
621-
$this->Loader->toEnv(false);
622-
$this->Loader->toEnv(false);
623-
}
624-
625583
/**
626584
* @covers \josegonzalez\Dotenv\Loader::putenv
627585
*/
@@ -664,6 +622,48 @@ public function testToPutenvException()
664622
$this->Loader->putenv(false);
665623
}
666624

625+
/**
626+
* @covers \josegonzalez\Dotenv\Loader::toEnv
627+
*/
628+
public function testToEnv()
629+
{
630+
$this->Loader->parse();
631+
$this->Loader->toEnv(false);
632+
633+
$this->assertEquals('bar', $_ENV['FOO']);
634+
$this->assertEquals('baz', $_ENV['BAR']);
635+
$this->assertEquals('with spaces', $_ENV['SPACED']);
636+
$this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']);
637+
}
638+
639+
/**
640+
* @covers \josegonzalez\Dotenv\Loader::toEnv
641+
*/
642+
public function testToEnvSkip()
643+
{
644+
$this->Loader->parse();
645+
$this->Loader->skipExisting('toEnv');
646+
$this->Loader->toEnv(false);
647+
$this->Loader->toEnv(false);
648+
649+
$this->assertEquals('bar', $_ENV['FOO']);
650+
$this->assertEquals('baz', $_ENV['BAR']);
651+
$this->assertEquals('with spaces', $_ENV['SPACED']);
652+
$this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']);
653+
}
654+
655+
/**
656+
* @covers \josegonzalez\Dotenv\Loader::toEnv
657+
* @expectedException LogicException
658+
* @expectedExceptionMessage Key "FOO" has already been defined in $_ENV
659+
*/
660+
public function testToEnvException()
661+
{
662+
$this->Loader->parse();
663+
$this->Loader->toEnv(false);
664+
$this->Loader->toEnv(false);
665+
}
666+
667667
/**
668668
* @covers \josegonzalez\Dotenv\Loader::toServer
669669
*/

0 commit comments

Comments
 (0)