Example #1
0
 /**
  * @param RoleFinder $roleFinder
  */
 public function __construct(RoleFinder $roleFinder)
 {
     foreach ($roleFinder->getAll() as $role) {
         $this->addRole($role->getRoleId(), $role->getParents());
     }
     $this->addResource('article');
     $this->allow('root', self::ALL, self::ALL);
     $this->allow('guest', 'article', Article::PERMISSION_VIEW, function (Permission $acl, $role, $resource, $privilege) {
         /** @var Article $article */
         $article = $acl->getQueriedResource();
         return $article->isPublished();
     });
 }
Example #2
0
 /**
  * @param string $roleStringIdentifier
  * @param User $user
  * @return UserRole
  * @throws RoleDoesNotExistException
  */
 public function assignByString(string $roleStringIdentifier, User $user) : UserRole
 {
     $role = $this->roleFinder->findByStringIdentifier($roleStringIdentifier);
     return $this->assign($role, $user);
 }