Skip to content

[5.8] Reworked env to allow getenv/putenv to be disabled #928

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 2 additions & 5 deletions src/Bootstrap/LoadEnvironmentVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
namespace Laravel\Lumen\Bootstrap;

use Dotenv\Dotenv;
use Dotenv\Environment\DotenvFactory;
use Illuminate\Support\Env;
use Dotenv\Exception\InvalidFileException;
use Dotenv\Environment\Adapter\PutenvAdapter;
use Dotenv\Environment\Adapter\EnvConstAdapter;
use Dotenv\Environment\Adapter\ServerConstAdapter;
use Symfony\Component\Console\Output\ConsoleOutput;

class LoadEnvironmentVariables
Expand Down Expand Up @@ -68,7 +65,7 @@ protected function createDotenv()
return Dotenv::create(
$this->filePath,
$this->fileName,
new DotenvFactory([new EnvConstAdapter, new PutenvAdapter, new ServerConstAdapter])
Env::getFactory()
);
}

Expand Down
47 changes: 0 additions & 47 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?php

use PhpOption\Option;
use Illuminate\Container\Container;
use Dotenv\Environment\DotenvFactory;
use Laravel\Lumen\Bus\PendingDispatch;
use Illuminate\Contracts\Bus\Dispatcher;
use Dotenv\Environment\Adapter\PutenvAdapter;
use Dotenv\Environment\Adapter\EnvConstAdapter;
use Dotenv\Environment\Adapter\ServerConstAdapter;

if (! function_exists('abort')) {
/**
Expand Down Expand Up @@ -148,48 +143,6 @@ function encrypt($value)
}
}

if (! function_exists('env')) {
/**
* Gets the value of an environment variable.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function env($key, $default = null)
{
static $variables;

if ($variables === null) {
$variables = (new DotenvFactory([new EnvConstAdapter, new PutenvAdapter, new ServerConstAdapter]))
->createImmutable();
}

return Option::fromValue($variables->get($key))
->map(function ($value) {
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}

return $value;
})
->getOrCall(function () use ($default) {
return value($default);
});
}
}

if (! function_exists('event')) {
/**
* Dispatch an event and call the listeners.
Expand Down