PHPackages                             adhocore/env - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. adhocore/env

ActiveLibrary

adhocore/env
============

Environment variable loader and retriever for PHP

v0.1.0(6y ago)2310.0k↓28.1%21MITPHPPHP &gt;=5.4CI failing

Since Oct 22Pushed 3y ago4 watchersCompare

[ Source](https://github.com/adhocore/php-env)[ Packagist](https://packagist.org/packages/adhocore/env)[ RSS](/packages/adhocore-env/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (8)Used By (1)

adhocore/env
------------

[](#adhocoreenv)

[![Latest Version](https://camo.githubusercontent.com/81085cb99a6228f12ef0af70cbf4a1ad54b8e8bbc01fff830709b7a1995a81ed/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6164686f636f72652f7068702d656e762e7376673f7374796c653d666c61742d737175617265)](https://github.com/adhocore/php-env/releases)[![Travis Build](https://camo.githubusercontent.com/87d281b2a0fb40cd3e32f71aa0b7c4987bc28707a386f9290cd7e3a5104104c9/68747470733a2f2f7472617669732d63692e6f72672f6164686f636f72652f7068702d656e762e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/adhocore/php-env?branch=master)[![Scrutinizer CI](https://camo.githubusercontent.com/b944b98e4df5d137e53ea75fcb26dbc38fe4a517189068992e04dda9acfab32b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6164686f636f72652f7068702d656e762e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/adhocore/php-env/?branch=master)[![Codecov branch](https://camo.githubusercontent.com/d6b9ebb7abdb77316253bfe9448012f99eae908971cff6e42528523272568b50/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6164686f636f72652f7068702d656e762f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/adhocore/php-env)[![StyleCI](https://camo.githubusercontent.com/5e0b1d9fda5072a8d89db223bf119e28c9730618410f1f71855149a157974410/68747470733a2f2f7374796c6563692e696f2f7265706f732f3130373731353230382f736869656c64)](https://styleci.io/repos/107715208)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

- Environment variable loader and retriever for PHP.
- Sanitization/Filters can be applied on retrieval if `filter` extension is loaded.
- Using env to configure application is one of the [12 postulates](https://12factor.net/config).

Installation
------------

[](#installation)

```
composer require adhocore/env

```

Usage
-----

[](#usage)

### Loading

[](#loading)

```
use Ahc\Env\Loader;

// Load env variables from .env file to `putenv` by default:
(new Loader)->load('/project/root/.env');

// Pass in boolean second param to control if the env should be reloaded:
(new Loader)->load('/project/root/.env', true);

// Load to $_SERVER global:
(new Loader)->load('/project/root/.env', true, Loader::SERVER);

// Load to $_ENV global and putenv():
(new Loader)->load('/project/root/.env', true, Loader::ENV | Loader::PUTENV);

// Load to all targets:
(new Loader)->load('/project/root/.env', true, Loader::ALL);
```

> Always wrap complex values within double quotes in `.env` file. Eg: `APP_KEY="K&^¢*&D(?
