-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Filled out the Readme with a little description and examples * edit readme * Revert "edit readme" This reverts commit 6aa9b4d. * edit readme #2
- Loading branch information
Showing
1 changed file
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,54 @@ | ||
# EnvReader | ||
PHP Environment Reader | ||
### 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](https://github.com/symfony/symfony/blob/6.2/src/Symfony/Component/DependencyInjection/EnvVarProcessor.php) from Symfony. | ||
|
||
Actual included Types are: | ||
|
||
- integer | ||
- float | ||
- string | ||
- boolean | ||
|
||
You can add your own Type by creating a class which implements the TypeInterface. | ||
|
||
Example: | ||
```php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Company\EnvTypes; | ||
|
||
use Freesoftde\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 | ||
<?php | ||
|
||
use Company\EnvTypes\CustomType; | ||
|
||
$env = Env::getInstance(); | ||
// add custom type | ||
$env->getCollection()->addItem(new CustomType()); | ||
|
||
// read Env | ||
$var = $env->get('FOO', 'custom_type'); | ||
|
||
``` |