Static helper to get environment variables in a Symfony 4+ app, loaded either from .env or .env.local.php

v0.0.1 2019-02-28 21:42 UTC

This package is auto-updated.

Last update: 2024-10-29 05:46:46 UTC


README

Latest Stable Version Build Status Coverage Status License

Usage

Add the package to your project :

composer require mesavolt/env

Use Mesavolt\Env::has() to test if an environment variable exists in your app and Mesavolt\Env::get() to retrieve it.

Quick note: By default, Env::get($name) throws an exception when the variable is defined but is empty. Use Env::getSafe($name) to not throw an exception and get the empty value.

APP_SECRET="i can see dead people"
EMPTY_VAR=

Use it in your project :

<?php

use Mesavolt\Env;

$secret = Env::get('APP_SECRET');
$empty = Env::getSafe('EMPTY_VAR');

Testing

composer dump-autoload # make sure vendor/autoload.php exists
./vendor/bin/phpunit