All Projects → oscarotero → Env

oscarotero / Env

Licence: mit
Simple library to read environment variables and convert to simple types.

Projects that are alternatives of or similar to Env

Dotenv Flow
Loads environment variables from .env.[development|test|production][.local] files for Node.js® projects.
Stars: ✭ 537 (+635.62%)
Mutual labels:  environment-variables
Ionic2 Environment Variables
Demonstration on how to easily setup environment variables in Ionic 2
Stars: ✭ 20 (-72.6%)
Mutual labels:  environment-variables
Sweet
Official repository for Semantic Web for Earth and Environmental Terminology (SWEET) Ontologies
Stars: ✭ 69 (-5.48%)
Mutual labels:  environment-variables
Musthave
A Node.js helper module for checking object elements against a list of required elements.
Stars: ✭ 5 (-93.15%)
Mutual labels:  environment-variables
Dotenv sekrets
Seamlessly encrypt/decrypt/edit your rails Dotenv files with the help of the Sekrets gem
Stars: ✭ 25 (-65.75%)
Mutual labels:  environment-variables
Env Cmd
Setting environment variables from a file
Stars: ✭ 969 (+1227.4%)
Mutual labels:  environment-variables
Psl
PHP Standard Library - a modern, consistent, centralized, well-typed set of APIs for PHP programmers.
Stars: ✭ 329 (+350.68%)
Mutual labels:  environment-variables
Dotenv Java
🗝️ Dotenv is a no-dep, pure Java module that loads environment variables from a .env file
Stars: ✭ 72 (-1.37%)
Mutual labels:  environment-variables
Environ
Library for managing environment variables in Clojure
Stars: ✭ 855 (+1071.23%)
Mutual labels:  environment-variables
Variable Injector
Continuous Integration Tool for Swift Projects
Stars: ✭ 63 (-13.7%)
Mutual labels:  environment-variables
Go Envparser
a go generator based env to go-struct decoder.
Stars: ✭ 17 (-76.71%)
Mutual labels:  environment-variables
Environment
Type-safe environment variables in Swift.
Stars: ✭ 24 (-67.12%)
Mutual labels:  environment-variables
Dotenv Webpack
A secure webpack plugin that supports dotenv and other environment variables and only exposes what you choose and use.
Stars: ✭ 1,022 (+1300%)
Mutual labels:  environment-variables
Environs
simplified environment variable parsing
Stars: ✭ 631 (+764.38%)
Mutual labels:  environment-variables
Conf
Go package for loading program configuration from multiple sources.
Stars: ✭ 70 (-4.11%)
Mutual labels:  environment-variables
Sync Dotenv
Keep your .env in sync with .env.example
Stars: ✭ 393 (+438.36%)
Mutual labels:  environment-variables
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (-61.64%)
Mutual labels:  environment-variables
Env Providers
👷 Load Laravel service providers based on your application's environment.
Stars: ✭ 73 (+0%)
Mutual labels:  environment-variables
Senv
Friends don't let friends leak secrets on their terminal window 🙈
Stars: ✭ 71 (-2.74%)
Mutual labels:  environment-variables
Properties
This library provides convinient way to work with properties. It can handle property-files on hard drive, in classpath or get values from system properties
Stars: ✭ 49 (-32.88%)
Mutual labels:  environment-variables

env

Software License Build Status Quality Score Total Downloads

Simple library to get environment variables converted to simple types.

Installation

This package is installable and autoloadable via Composer as oscarotero/env.

$ composer require oscarotero/env

Example

use Env\Env;

// Using getenv function:
var_dump(getenv('FOO')); //string(5) "false"

// Using Env:
var_dump(Env::get('FOO')); //bool(false)

Available conversions

  • "false" is converted to boolean false
  • "true" is converted to boolean true
  • "null" is converted to null
  • If the string contains only numbers is converted to an integer
  • If the string has quotes, remove them

Options

To configure the conversion, you can use the following constants (all enabled by default):

  • Env::CONVERT_BOOL To convert boolean values
  • Env::CONVERT_NULL To convert null values
  • Env::CONVERT_INT To convert integer values
  • Env::STRIP_QUOTES To remove the quotes of the strings

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::USE_SERVER_ARRAY To get the values from $_SERVER, instead getenv().
  • Env::LOCAL_FIRST To get first the values of locally-set environment variables.
use Env\Env;

//Convert booleans and null, but not integers or strip quotes
Env::$options = Env::CONVERT_BOOL | Env::CONVERT_NULL;

//Add one more option
Env::$options |= Env::USE_ENV_ARRAY;

//Remove one option
Env::$options ^= Env::CONVERT_NULL;

Default value

By default, if the value does not exist, returns null, but you can change for any other value:

use Env\Env;

Env::$default = false;

The env() function

You can use the env() function, like in Laravel or other frameworks:

use function Env\env;

var_dump(env('FOO'));

Please see CHANGELOG for more information about recent changes.

The MIT License (MIT). Please see LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].