wyrihaximus / react-http-middleware-session
处理会话的 react/http 中间件
4.1.0
2021-03-17 20:21 UTC
Requires
- php: ^8 || ^7.4
- ext-session: ^8 || ^7.4
- hansott/psr7-cookies: ^3.0.2
- psr/http-message: ^1.0.1
- react/cache: ^1.1.1
- react/http: ^1.2
- react/promise: ^2.8
- thecodingmachine/safe: ^1.3.3
Requires (Dev)
- wyrihaximus/async-test-utilities: ^3.4.18
This package is auto-updated.
Last update: 2024-09-04 19:23:14 UTC
README
安装
要通过 Composer 安装,请使用以下命令,它将自动检测最新版本并将其绑定到 ^
。
composer require wyrihaximus/react-http-middleware-session
此中间件负责处理会话。它使用 react/cache
进行存储或任何实现 React\Cache\CacheInterface
的缓存处理器。
用法
$server = new Server( $loop, /** Other Middleware */ new SessionMiddleware( 'CookieName', $cache, // Instance implementing React\Cache\CacheInterface [ // Optional array with cookie settings, order matters 0, // expiresAt, int, default '', // path, string, default '', // domain, string, default false, // secure, bool, default false // httpOnly, bool, default ], ), /** Other Middleware */ function (ServerRequestInterface $request) { $session = $request->getAttribute(SessionMiddleware::ATTRIBUTE_NAME); // Overwrite session contents, the details of changing specific keys is up to you $session->setContents([ 'foo' => 'bar', ]); // Get session contents var_export($session->getContents()); // Prints something like: ['foo' = 'bar'] return new Response(); } );
响应缓存
如果与 wyrihaximus/react-http-middleware-response-cache
一起使用此中间件,请参阅 wyrihaximus/react-http-middleware-response-cache-session-cache-configuration
,以确保不会缓存具有活动会话的用户响应。
数组转换
如果需要将会话传递给子进程,则它具有 toArray
和 fromArray
方法
$array = $session->toArray(); // Transfer to child process $session = (new Session('', [], new RandomBytes()))->fromArray($array); // The same can be done transferring changes back to the parent
许可证
MIT 许可证 (MIT)
版权所有 © 2020 Cees-Jan Kiewiet
在此条件下,任何人获得本软件及其相关文档副本(“软件”)的副本,均可免费处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向提供软件的人员做上述事项,前提是
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
本软件按“原样”提供,不提供任何形式的保证,明示或暗示,包括但不限于适销性、特定目的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论基于合同、侵权或其他原因,无论源于、因之或与此软件或其使用或其他交易有关。