Create a permissions for a resource.

@param $resource
@param bool $system
@return \Illuminate\Support\Collection
349790
public static function createResource($resource, $system = false)
    {
        $group        = ucfirst($resource);
        $slug         = strtolower($group);
        $permissions  = [
            [
                'slug'     => $slug . '.view',
                'resource' => $group,
                'name'     => 'View ' . $group,
                'system'   => $system,
            ],
            [
                'slug'     => $slug . '.create',
                'resource' => $group,
                'name'     => 'Create ' . $group,
                'system'   => $system,
            ],
            [
                'slug'     => $slug . '.update',
                'resource' => $group,
                'name'     => 'Update ' . $group,
                'system'   => $system,
            ],
            [
                'slug'     => $slug . '.delete',
                'resource' => $group,
                'name'     => 'Delete ' . $group,
                'system'   => $system,
            ],
        ];

        $collection = new Collection;
        foreach ($permissions as $permission) {
            try {
                $collection->push(static::create($permission));
            } catch (\Exception $e) {
                // permission already exists.
            }
        }

        return $collection;
    }
802811
public static function createFromObject($permission)
    {
        // Make sure the id is typecast to an integer.
        $id = ! is_null($permission->resource_id) ? (int) $permission->resource_id : null;

        if ($permission->type === Privilege::TYPE) {
            return new Privilege(
                $permission->action,
                new SimpleResource($permission->resource_type, $id)
            );
        } elseif ($permission->type === Restriction::TYPE) {
            return new Restriction(
                $permission->action,
                new SimpleResource($permission->resource_type, $id)
            );
        } else {
            throw new InvalidPermissionType("The permission type you provided \"{$permission->type}\" is incorrect.");
        }
    }
478148
public static function fromResources(ResourceInterface ...$resources) {
		$collectionDocument = new self();
		
		foreach ($resources as $resource) {
			$collectionDocument->addResource($resource);
		}
		
		return $collectionDocument;
	}
235957
public static function fromResource(Resource $resource)
    {
        if (isset($resource->query['with_billets'])) {
            return static::withBillets($resource);
        }
        return parent::fromResource($resource);
    }
91548
protected function checkRoleResource($role, $resource)
    {
        $resource = $this->checkResource($resource);
        $role = $this->checkRole($role);
        $roleId = ($role->getRoleId() == null) ? StorageInterface::ALL_ROLES : $role->getRoleId();
        $resrcId = ($resource->getResourceId() == null) ? StorageInterface::ALL_RESOURCES : $resource->getResourceId();
        if (!isset($this->permission[$roleId][self::NODE_RESOURCES][$resrcId][self::NODE_PERMISSION])) {
            $this->permission[$roleId][self::NODE_RESOURCES][$resrcId][self::NODE_PERMISSION] = [];
        }

        return $this;
    }
1105301
public function getResourceUserPermission(ResourceInterface $resource, UserInterface $user)
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId AND r.user=:user')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->setParameter('user', $user)
            ->getQuery();

        return $query->getOneOrNullResult();
    }
183188
protected function getUserPermissions($user)
    {
        $permissions = $this->manager->getDriver()->getCallerPermissions($user);
        $collection = new Collection();
        foreach ($permissions as $permission) {
            if ($permission instanceof Restriction) {
                continue;
            }
            $collection->allow($permission->getAction(), $permission->getResourceType(), $permission->getResourceId());
        }
        return $collection;
    }
1231821
public function optionsAction( $resource )
	{
		$response = $this->createAdmin( $resource )->options( $this->getPsrRequest(), new Response() );
		return $this->setPsrResponse( $response );
	}
13827
public function remove($resource)
    {
        $keysToRemove = array_keys($this->collection, $resource, true);
        $this->collection = array_values(array_diff_key($this->collection, array_flip($keysToRemove)));
        return $this;
    }
220009
public function load(FilesystemResource $resource)
    {

        if(!$this->validateExtension($resource)){
            return false;
        }

        return $this->transform($resource);
    }
535812
public function isAllowed($resource = Nette\Security\IAuthorizator::ALL, $privilege = Nette\Security\IAuthorizator::ALL)
	{
		$defaultNamespace = null;

		if (strpos($resource, ":") !== false) {
			$exploded = explode(":", $resource);
			if (count($exploded) == 2) {
				list($namespace, $resource) = $exploded;
				$defaultNamespace = $this->namespacesRepository->getDefaultNamespace();
				$this->namespacesRepository->setCurrentNamespace($namespace);
			}
		}

		foreach ($this->getRoles() as $role) {
			if ($this->getAuthorizator()->isAllowed($role, $resource, $privilege)) {
				$this->namespacesRepository->setCurrentNamespace($defaultNamespace);
				return true;
			}
		}

		$this->namespacesRepository->setCurrentNamespace($defaultNamespace);
		return false;
	}
339588
public function giveRolePermission($role, $permission, $level = 'allow')
    {
        $this->checkPermissionLevel($level);

        $role       =   $this->findRoleByKey($role);
        $permission =   $this->findPermissionByKey($permission);

        return $role->give($permission, $level);
    }
1204582
public function hasPermission($permissionName, Subject $subject, Resource $resource = null, array $params = [])
    {
        return in_array($permissionName, $this->getPermissions($subject, $resource, $params));
    }
1027176
public static function allPermissionsFor($resource)
    {
        $result = [];
        foreach (static::$permissions as $permission) {
            $result[] = sprintf('%s %s', $permission, str_plural($resource));
        }

        return $result;
    }
311052
public function load($resource)
    {
        if ($issue = $this->getIssue($resource)) {
            return $this->createFeature($issue);
        }

        return $this->createFeatures();
    }
960123
public function by($resource)
    {
        $resourceName = $resource instanceof AppliesToResource ? $resource->resourceName() : $resource;

        return new static($this->model, $resourceName);
    }
764389
public function putAction( $resource )
	{
		$response = $this->createAdmin( $resource )->put( $this->getPsrRequest(), new Response() );
		return $this->setPsrResponse( $response );
	}