A library to marshall environment variables from environments

1.0.0 2020-05-24 20:04 UTC

This package is auto-updated.

Last update: 2024-04-19 22:11:14 UTC


README

Build Status Total Downloads Coverage Status License Scrutinizer Code Quality

php-env

🌎 An Environment Abstraction for PHP 🌎

Use Cases

If you want a boundary between you and your runtime environment, this library can help. If you like to use .env files this library can help.

Installation

composer require remotelyliving/php-env

Usage

Create The Application Environment

<?php
// needs to be set before hand through docker or could grab the app environment from cli args
// EnvironmentType is an enum that you can extend to add more values to
$envType = new EnvironmentType(getenv('ENVIRONMENT'));
$envFile = "/my/app/envs/.{$envType}.env";

// we can now create the app environment
$env = Environment::createWithEnvFile($envType, $envFile);

// tells you which environment you're in
$env->is(EnvironmentType::DEVELOPMENT()); // true
$env->is(EnvironmentType::PRODUCTION()); // false

// tells you if a var exists
$env->has('FOO'); // true

// returns a value caster of a value that can then be called to get stricter types 
$env->get('FOO')->asArray();
$env->get('BAR')->asBoolean();
$env->get('BAR')->asInteger();