Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil committed Jun 23, 2023
1 parent 5605f41 commit 32c1b76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased

* Ability to load a Context from a dotenv file
* Add support for loading the context's environment from a dotenv file

## 0.5.1 (2023-06-22)

Expand Down
21 changes: 21 additions & 0 deletions doc/05-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,24 @@ function foo(Context $context): void
run('pwd'); // will print /tmp
}
```

## Load a context from dotenv file

You can also load your context from a dotenv file:

```php
use Castor\Attribute\AsContext;
use Castor\Context;

#[AsContext]
function my_context(): Context
{
return new Context::fromDotEnv();
}
```

By default, it loads the `.env` file on your project root (where castor file or
folder was found), but you can overload this by passing your dotenv file
path as an argument.
You can find more about how dotenv file loading and overloading works on
[related Symfony documentation](https://symfony.com/doc/current/configuration.html#configuring-environment-variables-in-env-files).

0 comments on commit 32c1b76

Please sign in to comment.