Skip to content

Commit

Permalink
Merge pull request #6 from ewake/master
Browse files Browse the repository at this point in the history
added support for getenv() local_only parameter
  • Loading branch information
oscarotero committed Apr 3, 2019
2 parents 635c1b2 + 8e7cc15 commit 665ff11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ To configure the conversion, you can use the following constants (all enabled by
There's also additional settings that you can enable (they're disabled by default)

* `Env::USE_ENV_ARRAY` To get the values from `$_ENV`, instead `getenv()`.
* `Env::LOCAL_FIRST` To get first the values of locally-set environment variables`.

```php
//Convert booleans and null, but not integers or strip quotes
Expand Down
3 changes: 3 additions & 0 deletions src/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Env
const CONVERT_INT = 4;
const STRIP_QUOTES = 8;
const USE_ENV_ARRAY = 16;
const LOCAL_FIRST = 32;

public static $options = 15; //All flags enabled
public static $default = null; //Default value if not exists
Expand Down Expand Up @@ -37,6 +38,8 @@ public static function get($name)
{
if (self::$options & self::USE_ENV_ARRAY) {
$value = isset($_ENV[$name]) ? $_ENV[$name] : false;
} elseif (self::$options & self::LOCAL_FIRST) {
$value = getenv($name, true) ?: getenv($name);
} else {
$value = getenv($name);
}
Expand Down

0 comments on commit 665ff11

Please sign in to comment.