https://github.com/brace-project/brace-mod-session
Session middleware for Brace Core Applications
https://github.com/brace-project/brace-mod-session
middleware-modul php-session
Last synced: 2 months ago
JSON representation
Session middleware for Brace Core Applications
- Host: GitHub
- URL: https://github.com/brace-project/brace-mod-session
- Owner: brace-project
- License: mit
- Created: 2021-02-16T11:48:10.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-08-20T10:07:28.000Z (over 1 year ago)
- Last Synced: 2026-01-11T06:37:20.581Z (3 months ago)
- Topics: middleware-modul, php-session
- Language: PHP
- Homepage: https://infracamp.org/
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/brace-project/brace-mod-session/actions)
[](//packagist.org/packages/brace/mod-session)
[](//packagist.org/packages/brace/mod-session)
[](//packagist.org/packages/brace/mod-session)
# brace-mod-session
Session middleware for Brace Core Applications
### Installation
```sh
composer require brace/mod-session
```
### Usage
You can use the `Brace\Session\SessionMiddleware` in any
[Brace Core Application](https://github.com/brace-project/brace-core).
this would look like following:
```php
\Brace\Core\AppLoader::extend(function (\Brace\Core\BraceApp $app) {
(/*.....*/)
$app->setPipe([
new \Brace\Session\SessionMiddleware(
new \Brace\Session\Storages\FileSessionStorage("/tmp"), // replace this with your chosen storage type and connection string
3600, // 1 hour ttl
86400 // 1 day expiration time
),
(/*.....*/)
]);
});
```
After this, you can access the session data inside any route/middleware that
has access to the `\Brace\Core\BraceApp` :
```php
AppLoader::extend(function (BraceApp $app) {
$app->router->on("GET@/", function() use ($app) {
$session = $app->get(SessionMiddleware::SESSION_ATTRIBUTE);
$session->set('foo', 'bar');
(/*....*/)
return $response;
});
});
```
### Examples
### Contributing
Please refer to the [contributing notes](CONTRIBUTING.md).
### License
This project is made public under the [MIT LICENSE](LICENSE)