dkx/slim-security

This package is abandoned and no longer maintained. No replacement package was suggested.

Security package for slim framework

0.0.1 2019-06-26 14:18 UTC

This package is auto-updated.

Last update: 2024-01-27 01:02:53 UTC


README

Security package inspired by symfony security and voters. Based on dkx/security.

Only for class routes.

See dkx/security for complete documentation.

Installation

$ composer require dkx/security dkx/slim-security

Usage

<?php

use DKX\Security\Security;
use DKX\SlimSecurity\SecuredRequestResponse;
use Doctrine\Common\Annotations\AnnotationReader;
use Slim\Container;

$container = new Container;
$container['foundHandler'] = function() use ($container) {
    $original = $container->get('foundHandler');
    
    return new SecuredRequestResponse(
        $original,
        new Security,
        new AnnotationReader
    );
};

Annotate controllers

<?php

use DKX\SlimSecurity\Annotations\IsGranted;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
 * @IsGranted("ROLE_ADMIN")
 */
final class DetailController
{
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        return $response;
    }
}