Skip to content

PSR-15 middleware that makes it possible to add conditional middlewares, based on request

License

Notifications You must be signed in to change notification settings

zakirullin/conditional-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zakirullin/conditional-middleware

Build Status Scrutinizer PHP from Packagist GitHub commits Software License

PSR-15 middleware that makes it possible to add conditional middlewares, based on request

Requirements

Installation

This package is installable and autoloadable via Composer as 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'),
    ...
]);

Options

__construct(
    callable $shouldProtect,
    callable $getIdentity,
    string $secret,
    string $attribute = self::ATTRIBUTE,
    int $ttl = self::TTL,
    string $algorithm = self::ALGORITHM
)

name(string $name)

The session name. If it's not defined, the default PHPSESSID will be used.


The MIT License (MIT). Please see LICENSE for more information.

About

PSR-15 middleware that makes it possible to add conditional middlewares, based on request

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages