定制 maatwebsite/usher 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

maatwebsite/usher

最新稳定版本:1.0.3

Composer 安装命令:

composer require maatwebsite/usher

包简介

A Doctrine ACL package for Laravel

README 文档

README

A Doctrine ACL package for Laravel 5

  • Login with Doctrine User entity
  • User roles
  • User banning
  • User suspending
  • User permissions
  • User last login and last attempt event listeners
  • Role permissions

Installation

Include the service provider in config/app.php

'Brouwers\LaravelDoctrine\DoctrineServiceProvider',
'Maatwebsite\Usher\UsherServiceProvider'

Config

To change the defaults of this package, publish the config:

php artisan vendor:publish --provider="Maatwebsite\Usher\UsherServiceProvider"

Default usage

Out of the box, you can use the ACL system without defining your own entities. However this is not recommended!

Custom usage

For example if you want a Customer and Group entity, you just have to make sure it implements Maatwebsite\Usher\Contracts\Users\User. If you want a faster solution, you can optionally extend the MappedSuperclass Maatwebsite\Usher\Domain\Users\User. *Note that you will have to define the roles relation yourself.

Example with the MappedSuperclass:


use Doctrine\ORM\Mapping as ORM;
use Maatwebsite\Usher\Domain\Users\User;
use Maatwebsite\Usher\Contracts\Users\User as UserInterface;

/**
 * @ORM\Entity(repositoryClass="DoctrineCustomerRepository")
 * @ORM\Table(name="customers")
 * @ORM\HasLifecycleCallbacks()
 */
class Customer extends User implements UserInterface
{
    /**
     * @ORM\ManyToMany(targetEntity="Group", inversedBy="customers")
     * @ORM\JoinTable(name="customer_groups")
     * @var ArrayCollection|\App\Domain\Customers\Entities\Role[]
     */
    protected $groups;
    
    /**
     * Customer Constructor
     */
    public function __construct()
    {
        $this->groups = new ArrayCollection();
    }
    
    /**
     * @return ArrayCollection|\Maatwebsite\Usher\Contracts\Roles\Role[]
     */
    public function getRoles()
    {
        return $this->groups;
    }
  }

Same as with the User MappedSuperclass, you'll have to define the User relation yourself.

/**
 * @ORM\Entity(repositoryClass="DoctrineRoleRepository")
 * @ORM\Table(name="groups")
 * @ORM\HasLifecycleCallbacks()
 */
class Group extends Role implements RoleInterface
{

    /**
     * @ORM\ManyToMany(targetEntity="Customer", mappedBy="groups")
     * @var ArrayCollection|Customer[]
     **/
    protected $customers;

    /**
     * Role Constructor
     */
    public function __construct()
    {
        $this->customers = new ArrayCollection();
    }

    /**
     * @return ArrayCollection|\Maatwebsite\Usher\Contracts\Users\User[]
     */
    public function getUsers()
    {
        return $this->customers;
    }
}

Next you'll have to update the class reference in config/usher.php for the user.entity en role.entity

return [
    'users'  => [
        'entity' => 'Customer'
    ],
    'roles'  => [
        'entity' => 'Group'
    ]
]

Events

Domain Events

Domain Event When
UserGotAssignedToRole $user->assignRole($role)
UserGotBanned $user->ban()
UserGotRemovedFromRole $user->removeRole($role)
UserGotSuspended $user->suspend($minutes)
UserRegistered $user->register()
UserUpdatedProfile $user->update()
RoleWasCreated $role->create()
RoleWasUpdated $role->update()

Event Listeners

Event listeners can be enabled and disabled inside the config. By default the listed listenes are all enabled.

Listener When
SaveLastAttemptDate auth.attempt
CheckIfUserIsBanned auth.attempt
CheckIfUserIsSuspended auth.attempt
SaveLastLoginDate auth.login

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 8
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固