Example #1
0
 /**
  * {@inheritdoc}
  *
  * @return $this
  */
 public function associate($role, $permission, $rule = GuardInterface::ALLOW)
 {
     if (!$this->hasRole($role)) {
         throw new RoleException("Undefined role '{$role}'.");
     }
     if ($rule !== GuardInterface::ALLOW) {
         if (!$this->rules->has($rule)) {
             throw new PermissionException("Invalid permission rule '{$rule}'");
         }
     }
     foreach ((array) $permission as $item) {
         $this->associations[$role][$item] = $rule;
     }
     return $this;
 }