Skip to content
/ env Public

This simple package helps you get environment variables with getenv.

License

Notifications You must be signed in to change notification settings

Arcesilas/env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scrutinizer build Scrutinizer coverage Scrutinizer code quality PHP version Packagist Version License Maintenance

Env

This simple package helps you get environment variables with getenv.

Installation

composer require arcesilas/env

Usage

use Arcesilas\Env\Env;

$debug = Env::get('DEBUG');
$dsn = Env::get('DSN', 'sqlite:memory:'); // Returns the DSN env value, "sqlite:memory:" if not set

You may prefer to use the function helper:

$debug = env('DEBUG');
$dsn = env('DSN', 'sqlite:memory:');

Default values

When an environment variable is not set, null is returned by default. You can specify a default value as the second argument.

The default value may be a Closure:

$foo = env('foo', function () {
    return 42;
});

The Closure will be executed and its result will be returned.

Types conversion

Some values are automatically converted to their native PHP equivalent type:

  • integers
  • floats
  • booleans
  • null

Booleans can be converted from the following (case insensitive) strings:

  • "true", "on", "yes" => true
  • "false", "off", "no" => false

About

This simple package helps you get environment variables with getenv.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages