madlines/common-security-resolver 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

madlines/common-security-resolver

最新稳定版本:1.1

Composer 安装命令:

composer require madlines/common-security-resolver

包简介

Simple voters-based access resolver

README 文档

README

Build Status

This is a very simple voters-bases security resolver. It gets a list of voters which work in a middleware fashion and it exposes a isGranted method which can ask voters if user can perform a specified task.

Voters don't have to implement any interface. To make that library more generic it uses duck typing instead. Voters need to be objects implementing one public method named as you like.

Tasks can be whatever you like. Those can be objects or just string. It's up to your voters to tell if they support it.

Usage:

Prepare a voter like that

<?php

class PostEditVoter
{
    public function isGranted($user, $task)
    {
        // if (!($task instanceof PostEditTask)) {
        if ($task !== 'post_edit') {
            return null; // null means 'ignore'
            // returning integer 0 means the same
        }

        if ($user->hasRole('ROLE_ADMIN')) {
            return true; // agree
            // returning integer 1 means the same
        }

        return false; // disagree
        // returning integer -1 means the same
    }
}

Create an instance of AccessResolver and add voters to it

$postEditVoter = new PostEditVoter();
// create more voters if you like

$resolver = new AccessResolver();

$resolver->addVoter($postEditVoter); // You can pass method name as second parameter. It defaults to `isGranted`
// add more voters if you like

Get your user from somewhere

$user = $this->getUser();

And ask for permission like that:

$resolver->isGranted($user, 'post_edit');
// or maybe $resolver->isGranted($user, $postEditTask);

统计信息

  • 总下载量: 81
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-14