Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gree/php-custom-environment-variables


https://github.com/gree/php-custom-environment-variables

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

CustomEnvironmentVariables
----

CustomEnvironmentVariables is inspired by [node-config](https://github.com/lorenwest/node-config)'s
[Custom Environment Variables](https://github.com/lorenwest/node-config/wiki/Environment-Variables#custom-environment-variables) feature.

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/gree/php-custom-environment-variables/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/gree/php-custom-environment-variables/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/gree/php-custom-environment-variables/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/gree/php-custom-environment-variables/?branch=master)

## Requirements

PHP 7.1+

## Installation

```bash
$ composer require wfs/custom-environment-variables
```

## Usage

Example code `usage.php` is:

```php
[
'name' => 'NAME',
'age' => 'AGE',
]
]);

$target = [
'employee' => [
'name' => 'alice',
'age' => '10',
]
];

$customized = $customizer->customize($target);

echo("name: {$customized['employee']['name']}" . PHP_EOL);
echo("age: {$customized['employee']['age']}" . PHP_EOL);
```

If you does not set any environment variables, `usage.php` result is:

```bash
$ php usage.php
name: alice
age: 10
```

If you set `NAME`, `usage.php` result is:

```bash
$ export NAME=bob
$ php usage.php
name: bob
age: 10
```

If you set `NAME` and `AGE`, `usage.php` result is:

```bash
$ export NAME=bob
$ export AGE=20
$ php usage.php
name: bob
age: 20
```

You will use `CustomEnvironmentVariables` with [Config](https://github.com/hassankhan/config).

Example code `config.php` is:

```php
[
'name' => 'NAME',
'age' => 'AGE',
]
]);

$target = new Config(<<customize($target);

echo("name: {$customized['employee']['name']}" . PHP_EOL);
echo("age: {$customized['employee']['age']}" . PHP_EOL);
```

result is:

```bash
$ export NAME=bob
$ export AGE=20
$ php config.php
name: alice
age: 10
name: bob
age: 20
```