zakirullin / conditional-middleware
基于请求添加条件中间件的PSR-15中间件
0.1.5
2019-04-25 09:25 UTC
Requires
- php: ^7.1
- middlewares/utils: ^2.1.1
- psr/http-message: ^1.0.1
- psr/http-server-middleware: ^1.0
- zendframework/zend-diactoros: ^1.7.0
Requires (Dev)
- phpunit/phpunit: ^7
- squizlabs/php_codesniffer: ^3.0
README
基于 request
的PSR-15中间件,可添加条件中间件
要求
- PHP >= 7.1
- 一个 PSR-7 http消息实现(例如 Diactoros、Guzzle、Slim 等...)
- 一个 PSR-15中间件分发器
安装
此软件包可以通过Composer以 zakirullin/conditional-middleware 的方式安装和自动加载。
composer require zakirullin/conditional-middleware
PHP
$shouldProtect = function (\Psr\Http\Message\ServerRequestInterface $request) { $handler = $request->getAttribute('handler'); return $handler != 'login'; }; $getIdentity = function (\Psr\Http\Message\ServerRequestInterface $request) { $session = $request->getAttribute('session'); return [$session->get('userId')]; }; $dispatcher = new Dispatcher([ ... new \Zakirullin\Middlewares\CSRF($shouldProtect, $getIdentity, 'secret'), ... ]);
选项
__construct( callable $shouldProtect, callable $getIdentity, string $secret, string $attribute = self::ATTRIBUTE, int $ttl = self::TTL, string $algorithm = self::ALGORITHM )
name(string $name)
会话名称。如果未定义,则默认使用 PHPSESSID
。
MIT许可证(MIT)。有关更多信息,请参阅 LICENSE。