Finds either role or permission or throws an exception if it is not found.

@param  string $name
@return Permission|Role|null
545365
protected function findItem($name)
    {
        $item = $this->authManager->getRole($name);

        if ($item instanceof Role) {
            return $item;
        }

        $item = $this->authManager->getPermission($name);

        if ($item instanceof Permission) {
            return $item;
        }

        return null;
    }
542564
protected function getBlock($name = null)
    {
        return ($name == null) ? $this->block : (isset($this->block[$name]) ? $this->block[$name] : false);
    }
1073330
public function checkRole( $role, $parent = null )
    {
        if ( null === $role )
        {
            return null;
        }

        if ( $role instanceof Acl\Role\RoleInterface )
        {
            $role = $role->getRoleId();
        }

        $acl = $this->getAcl();

        if ( ! $acl->hasRole( $role ) )
        {
            if ( null === $parent )
            {
                $parent = $this->getParentId( $role );
            }
            elseif ( $parent instanceof Acl\Role\RoleInterface )
            {
                $parent = $parent->getRoleId();
            }

            $parent = $this->checkRole( $parent );
            $acl->addRole( $role, (array) $parent );

            $matches    = array();
            $structures = array();

            if ( preg_match( '/^(\d+)$/', $role, $matches ) ) //group
            {
                $structures = $this->getMapper()
                                   ->findAllByGroupId( $matches[1] );
            }
            else if ( preg_match( '/^(\d+)\.(\d+)$/', $role, $matches ) ) //user
            {
                $structures = $this->getMapper()
                                   ->findAllByUserId( $matches[2] );

                $resource = 'user.group.' . $matches[1] .
                            '.identity.' . $matches[2];

                $this->checkResource( $resource );
                $acl->allow( $role, $resource );
            }

            foreach ( $structures as $structure )
            {
                $this->checkResource( $structure->resource );
                $acl->allow( $role, $structure->resource, $structure->privilege );
            }
        }

        return $role;
    }
771690
public function hasRole($name)
    {
        if (!$this->relationLoaded('role')) {
            $this->load('role');
        }

        return in_array($this->role->name, (is_array($name) ? $name : [$name]));
    }
564570
public function find( $name )
    {
        $name = (string) $name;
        $path = $this->getSavePath();

        if ( ! is_file( $path . $name ) )
        {
            return null;
        }

        return $this->createStructure( array(
            'name' => $name,
            'code' => @ file_get_contents( $path . $name ),
        ) );
    }
54739
public static function findOrCreate(string $name, $guardName = null): RoleContract
    {
        $guardName = $guardName ?? Guard::getDefaultName(static::class);

        $role = static::where('name', $name)->where('guard_name', $guardName)->first();

        if (! $role) {
            return static::query()->create(['name' => $name, 'guard_name' => $guardName]);
        }

        return $role;
    }
82259
public function iDontSeeRole( $name )
    {
        $role = $this->getRoleManager()->getRole( $name );
        Assertion::assertNull(
            $role,
            "Found Role with name $name"
        );
    }
1169749
public function get($name)
    {
        if (!isset($this->permissions[$name])) {
            throw new InvalidArgumentException("Permissions $name for type $objectType not found.");
        }

        return $this->permissions[$name];
    }
979373
public function findPermissionByKey($key)
    {
        if ($key instanceof PermissionInterface) {
            return $key;
        }

        $result =   $this->permissionProvider->findByKey($key);
        if ($result) {
            return $result;
        }

        $exceptionMessage   =   "The permission '%(key)s' cannot be found.";

        throw new PermissionNotFound(isprintf($exceptionMessage, compact('key')));
    }
824618
public function getPermission($name)
    {
        $permission = $this->parameters->get('permission');

        if (null === $permission) {
            throw new \LogicException('Current action does not require any authorization.');
        }

        if (true === $permission) {
            return sprintf('%s.%s.%s', $this->metadata->getApplicationName(), $this->metadata->getName(), $name);
        }

        return $permission;
    }
704872
public function getDirective($name)
    {
        if (!$this->initialized) {
            $this->initialize();
        }

        return isset($this->directives[$name]) ? $this->directives[$name] : null;
    }
665108
protected function createRole($name)
    {
        if (!isset($this->allRoles[$name])) {
            $this->allRoles[$name] = new Role($name);
        }

        return $this->allRoles[$name];
    }
617004
public function getRole($name)
    {
        if ($this->hasRole($name)) {
            return $this->roles[$name];
        }

        throw new \InvalidArgumentException(sprintf('No role with name "%s" could be found', $name));
    }
181310
public function setPermission($name, $description = null)
    {
        $permission = $this->getPermission($name) ?: $this->createPermission($name);
        if ($description) {
            $permission->description = $description;
        }
        $this->add($permission);

        return $permission;
    }
310331
public function permissionGetIdByName($name)
  {
    if(!array_key_exists((string) $name, $this->permissionList()))
    {
      throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid permission ID", 0xA02);
    }

    return $this->permissionList[(string) $name]["permid"];
  }
435867
public function iSeeRole( $name )
    {
        $role = $this->getRoleManager()->getRole( $name );
        Assertion::assertNotNull(
            $role,
            "Couldn't find Role with name $name"
        );
    }
1008207
public function ensureRoleExists( $name )
    {
         /** @var \eZ\Publish\API\Repository\Repository $repository */
        $repository = $this->getRepository();
        $that = $this;
        $role = $repository->sudo(
            function() use( $repository, $name, $that )
            {
                $role = null;
                $roleService = $repository->getRoleService();

                // make sure role name starts with uppercase as this is what default setup provides
                if ($name !== ucfirst($name)) {
                    @trigger_error(
                        "'{$name}' role name should start with uppercase letter",
                        E_USER_DEPRECATED
                    );
                }

                try
                {
                    $role = $roleService->loadRoleByIdentifier(ucfirst($name));
                }
                catch ( ApiExceptions\NotFoundException $e )
                {
                    $roleCreateStruct = $roleService->newRoleCreateStruct(ucfirst($name));
                    $roleDraft = $roleService->createRole( $roleCreateStruct );
                    $roleService->publishRoleDraft($roleDraft);
                    $role = $roleService->loadRole($roleDraft->id);
                    $that->addObjectToList( $role );
                }

                return $role;
            }
        );

        return $role;
    }