Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/lamoda/multi-env

Library that provides classes to work with envs in multitenant environment
https://github.com/lamoda/multi-env

environment environment-variables multitenant

Last synced: about 2 months ago
JSON representation

Library that provides classes to work with envs in multitenant environment

Awesome Lists containing this project

README

        

# Lamoda multi-env

[![Build Status](https://travis-ci.org/lamoda/multi-env.svg?branch=master)](https://travis-ci.org/lamoda/multi-env)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lamoda/multi-env/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lamoda/multi-env/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/lamoda/multi-env/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/lamoda/multi-env/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/lamoda/multi-env/badges/build.png?b=master)](https://scrutinizer-ci.com/g/lamoda/multi-env/build-status/master)

Library that provides classes to work with envs in multitenant environment

Library based on params passed to it on initialization stage will decide which env variable should be used
for current request.

## Installation

1. Install library with composer:
```bash
composer require lamoda/multi-env
```

## Usage

### Library usage examples to work in not multitenant environment (could be useful in development mode)

```php
getCurrentHost();
```
2. __\Lamoda\MultiEnv\HostDetector\CliArgsBasedHostDetector__ - use to identificate host via Cli script run
```php
getCurrentHost();
```

3. __\Lamoda\MultiEnv\HostDetector\FirstSuccessfulHostDetector__ - use to aggregate multiple HostDetector's
```php
getCurrentHost();
```

## Available FormatterInterface implementations
1. __\Lamoda\MultiEnv\Formatter\PrefixAppendFormatter__ - append prefix and delimiter to original string.
Combine __original string__, __delimiter__,__host id__ in order
\*__host id__\*, \*__delimiter__\*, \*__original string__\*
```php
formatName('originalEnvName', new HostId('test_host'));
```
2. __\Lamoda\MultiEnv\Formatter\SuffixAppendFormatter__ - append suffix and delimiter to original string.
Combine __original string__, __delimiter__,__host id__ in order
\*__original string__\*, \*__delimiter__\*, \*__host id__\*
```php
formatName('originalEnvName', new HostId('test_host'));
```
3. __\Lamoda\MultiEnv\Formatter\CharReplaceFormatter__ - act like __str_replace__ in PHP. Could be useful to replace illegal
char __'-'__ to __'\_\'__ when you access to env variable
```php
formatName('original-env-name', new HostId('testHost'));
```

4. __\Lamoda\MultiEnv\Formatter\FormatterPipeline__ - aggregate few formatters. Iterate through them and apply each to original stirng
```php
formatName('originalEnvName', new HostId('test-host-id'));
```