Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ddrv/php-env
Read variables from environment or .env file
https://github.com/ddrv/php-env
env environment environment-variables library php
Last synced: about 2 months ago
JSON representation
Read variables from environment or .env file
- Host: GitHub
- URL: https://github.com/ddrv/php-env
- Owner: ddrv
- License: mit
- Created: 2020-10-27T14:03:07.000Z (about 4 years ago)
- Default Branch: 2x
- Last Pushed: 2022-08-24T01:44:10.000Z (over 2 years ago)
- Last Synced: 2024-08-27T23:31:48.816Z (4 months ago)
- Topics: env, environment, environment-variables, library, php
- Language: PHP
- Homepage: https://packagist.org/packages/ddrv/env
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ddrv/env
> Read variables from environment or .env file
# Install
```text
composer require ddrv/env:^2.0
```# Usage
```text
# /path/to/project/.envAPP_VAR_3=value3
``````php
'value1',
* 'APP_VAR_2' => 'value2',
* ];
*/$env = new Env(
new EnvVariableProvider(),
new FileVariableProvider('/path/to/project/.env'),
);$env->get('APP_VAR_1'); // returns 'value1'
$env->get('APP_VAR_2'); // returns 'value2'
$env->get('APP_VAR_3'); // returns 'value3'
$env->get('APP_VAR_4'); // returns null
$env->get('APP_VAR_5', 'defaultValue'); // returns 'defaultValue'
```## Prefixes
```php
'value1',
* 'APP_VAR_2' => 'value2',
* ];
*/$env = new Env(
new PrefixedVariableProvider(new EnvVariableProvider(), 'APP_'),
new PrefixedVariableProvider(new FileVariableProvider('/path/to/project/.env'), 'APP_'),
);$env->get('VAR_1'); // returns 'value1'
$env->get('VAR_2'); // returns 'value2'
$env->get('VAR_3'); // returns 'value3'
$env->get('VAR_4'); // returns null
$env->get('VAR_5', 'defaultValue'); // returns 'defaultValue'
```