Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Nessier committed Jul 11, 2020
1 parent 9d03501 commit eb5c417
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,38 @@ Use the ```Neoflow\Session\Session``` and ```Neoflow\Session\Flash``` as helper
#### Initialization
You have 2 options to initialize the helper classes.

Add the classes to the container and get them as dependency injection:
Add the classes to the container...
```php
$container = new DI\Container();
$container
->set('session', function () {
return new Neoflow\Session\Session();
})
->set('flash', function () {
return new Neoflow\Session\Flash();
});
```
...and get them as dependency injection:
```php
$app->get('/', function (Request $request, Response $response) {
$session = $this->get('session');
$flash = $this->get('flash');

$container->set('session', function () {
return new Neoflow\Session\Session();
});
// Your custom code

$container->set('flash', function () {
return new Neoflow\Session\Flash();
return $response;
});
```

Or get them as request attributes by setting the session middleware option ```withAttribute``` to ```true```:
Or get them as request attributes, by setting the option ```withAttribute``` to ```true``` for the
```Neoflow\Session\Middleware\SessionMiddleware```:
```php
$app->get('/', function (Request $request, Response $response) {
$session = $request->getAttribute('session');
$flash = $request->getAttribute('flash');

// Your custom code

return $response;
});
```
Expand Down

0 comments on commit eb5c417

Please sign in to comment.