Giter VIP home page Giter VIP logo

envoi's Introduction

Envoi

Envoi aims to ease the use and documentation of environment variables (env vars) in PHP applications.

Envoi features:

  • a Yaml schema to describe the env vars that may be used to configure an application

  • tools to validate env vars against a schema

  • a tool to assist in the population of a .env file

  • a tool which converts a schema to markdown

Envoi sports a console command which validates a .env file against a schema (by convention, .env.yaml). It also provides checkers that, when invoked early in the start-up phase of an application, will halt an application which doesn't have a complete and valid set of env vars.

Install

composer require linkorb/envoi

Use

Env Checkers

A checker should be invoked as early as possible in the life-cycle of an application. The ideal time is immediately after the environment has been populated with env vars. For example, in a Symfony-based app, the checker should be invoked right after the Dotenv component has loaded the env vars from the various .env* files:

<?php

// config/bootstrap.php

use Envoi\EnvChecker;
use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';

(new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
// check the env!
(new EnvChecker())->check(dirname(__DIR__).'/.env.yaml');

The checker will throw an exception to halt the application when invalid env vars are found. The list of validation errors is included in the exception message.

EnvChecker treats the environment as immutable: it validates env vars, but does not modify them. MutableEnvChecker validates env vars and can also transform values, making it the ideal checker when you want to take advantage of the various env var transformation features of Envoi.

Interpolation

Assign one variable based on another in .env file

FOO="foo" 
BAR="{FOO}/logs"

Metadata environment example .env.yaml Supports types: int, string, url, path

FOO:
  description: Used to configure foo system
  type: url
  default: "https://username:[email protected]/bla"
  required: true
QUX:
  description: path to qux files
  type: path
  example: "some example value"
  make-absolute-path: true  #  "Expands  relative paths to absolute paths (i.e. ~/qux becomes /home/joe/qux)
BAR:
  description: Used for bar things
  type: string
  options: RED,GREEN,BLUE # validates that input is one of the available options

Init environment variables from .env

Envoi::init();
$foo = getenv('FOO');

CLI

./vendor/bin/envoi

Available commands:

validate Validate based on meta file .env.yaml.
configure CLI wizard to ask + update .env file based on .env.yaml.
markdown Output a GitHub Flavored Markdown documentation for the available variables. Look for a <!-- envoi start --> and <!-- envoi end --> tags in file (default to README.md), and insert/update the generated markdown between those tags.

Run tests

./vendor/bin/phpunit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.