devcirclede / env-reader
Simple Env Reader/Parser for PHP
Installs: 39
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 0
Open Issues: 4
Type:project
Requires
- php: >=8.1
Requires (Dev)
- overtrue/phplint: ^9.0
- phpunit/phpunit: ^10.0
- slevomat/coding-standard: ^8.8
- vimeo/psalm: ^5.7
README
EnvReader
PHP Environment Reader
Simple Environment Reader which can parse the Value to a specific type. It tries to find the Value in $_ENV, $_SERVER and via getenv. The logic is leaned on the EnvVarProcessor from Symfony.
Installation
composer require devcirclede/env-reader
Supported Types
Actual included Types are:
- integer
- float
- string
- boolean
- array
- json
You can add your own Type by creating a class which implements the TypeInterface.
Example:
<?php declare(strict_types=1); namespace Company\EnvTypes; use DevCircleDe\EnvReader\Types\TypeInterface; class CustomType implements TypeInterface { public function getName(): string { return 'custom'; } public function convert(string $value): mixed { // convert the value to custom type return $value; } }
Usage of the CustomType:
<?php use Company\EnvTypes\CustomType; use DevCircleDe\EnvReader\EnvParser; $envParser = EnvParser::getInstance(); // add custom type $envParser->getCollection()->addItem(new CustomType()); // read Env $var = $envParser->parse('FOO', 'custom_type');