承接 laravel-commode/filters 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

laravel-commode/filters

Composer 安装命令:

composer require laravel-commode/filters

包简介

README 文档

README

#Commode: Filters

Build Status Code Climate Coverage Status

_laravel-commode/filters is a laravel 4.2 Filter Layer helper, which allows you to organize your routing filters in classes.


####Contents

##Installing

You can install laravel-commode/common using composer:

"require": {
    "laravel-commode/filters": "dev-master"
}

To enable package you need to register LaravelCommode\Filters\FiltersServiceProvider service provider:

    <?php
        // ./yourLaravelApplication/app/config/app.php
        return [
            // ... config code
            'providers' => [
                // ... providers
                'LaravelCommode\Filters\FiltersServiceProvider'
            ]
        ];

##Creating a filter group

To create a filter group you need to create a FilterGroupClass, that must be extended from LaravelCommode\Filters\Groups\AbstractFilterGroup. Each FilterGroupClass needs to implement getPrefix() method, that would return prefix, that is common for methods that are going to be registered as filters. For example, let's say we need an ACL filter group, that could be checking whether user is guest or not, and check if current authorized user has permissions for actions. We will create ACLFilters class, that extends LaravelCommode\Filters\Groups\AbstractFilterGroup and implement getPrefix() method, that would return 'auth' value, since methods' names we're gonna need as filters are prefixes with this string:

    <?php
        namespace Application\Http\Filters;
        
        use LaravelCommode\Filters\Groups\AbstractFilterGroup;
        use Illuminate\Auth\Guard;
        use Illuminate\Foundation\Application;
        
        class ACLFilters extends AbstractFilterGroup
        {
            /**
            * @var \Illuminate\Auth\Guard 
            **/
            private $authGuard;
            
            /**
            * All constructors are passed into DI-container.
            *
            * But, since \Illuminate\Auth\Guard is registered as shared 
            * view name auth, it can not be injected directly, so in 
            * this example I will use Application injection
            **/
            public function __construct(Application $application)
            {
                $this->authGuard = $application->make('auth'); // grab auth guard from DI 
            }
            
            /**
            * Guest filter
            **/
            public function authGuest()
            {
                if ($this->authGuard->guest()) {
                    return \Redirect::to('security/signin');
                }
            }
            
            /**
            * Dashboard filter
            **/
            public function authDashboard()
            {
                if ($this->authGuest() && !$this->authGuard->user()->hasPermission('dashboard')) {
                    return \Redirect::to('security/signin');
                }
            }
            
            public function getPrefix()
            {
                return 'auth';
            }
        }

##Filter registry

Filter registry is a class that helps you to register your filter groups in laravel environment. It can be accessed through FilterRegistry facade, through laravel's IoC as 'common.filters' or by passing LaravelCommode\Filters\Interfaces\IFilterRegistry into it.

To register your filter group you need to pass it's class name into FilterRegistry::extract($classname) method or if you want to register multiple filter groups you need to use FilterRegistry::extractArray(array $classnames = []); if you have constructed filter group yourself, you can pass it's instance into FilterRegistry::add(\LaravelCommode\Filters\Interfaces\IFilterGroup $filterGroup).

    <?php
        FilterRegistry::extract('Application\Http\Filters\ACLFilters');
        FilterRegistry::extractArray([Application\Http\Filters\ACLFilters::class]); // php 5.5 style
        FilterRegistry::add(new Application\Http\Filters\ACLFilters(app()))
        

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-04-20