-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG Replace phpdotenv with thread-safe replacement
- Loading branch information
Damian Mooyman
authored and
Sam Minnée
committed
Oct 20, 2017
1 parent
b20bfd2
commit b9cb1e6
Showing
25 changed files
with
387 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Core; | ||
|
||
use M1\Env\Parser; | ||
|
||
/** | ||
* Loads environment variables from .env files | ||
* Loosely based on https://github.com/vlucas/phpdotenv/blob/master/src/Loader.php | ||
*/ | ||
class EnvironmentLoader | ||
{ | ||
/** | ||
* Load environment variables from .env file | ||
* | ||
* @param string $path Path to the file | ||
* @param bool $overload Set to true to allow vars to overload. Recommended to leave false. | ||
* @return array|null List of values parsed as an associative array, or null if not loaded | ||
* If overloading, this list will reflect the final state for all variables | ||
*/ | ||
public function loadFile($path, $overload = false) | ||
{ | ||
// Not readable | ||
if (!file_exists($path) || !is_readable($path)) { | ||
return null; | ||
} | ||
|
||
// Parse and cleanup content | ||
$result = []; | ||
$variables = Parser::parse(file_get_contents($path)); | ||
foreach ($variables as $name => $value) { | ||
// Conditionally prevent overloading | ||
if (!$overload) { | ||
$existing = Environment::getEnv($name); | ||
if ($existing !== false) { | ||
$result[$name] = $existing; | ||
continue; | ||
} | ||
} | ||
|
||
// Overload or create var | ||
Environment::setEnv($name, $value); | ||
$result[$name] = $value; | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.