Skip to content

Commit

Permalink
Readme-Update (#1)
Browse files Browse the repository at this point in the history
* 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
vansari authored Feb 20, 2023
1 parent 554b56a commit 45f2ef7
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion README.md
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');

```

0 comments on commit 45f2ef7

Please sign in to comment.