Adds a permission to the merged permissions Collection.
Override logic is handled from outside to enable strict or standard permissions.

@param Permission $permission
@param bool       $override
763036
protected function add(Permission $permission, $override = true)
    {
        if ($override || ! $this->permissions->containsKey($permission->getName()))
        {
            $this->permissions->set($permission->getName(), $permission);
        }
    }
564699
public function hasPermission($permission)
    {
        foreach($this->roles as $role){
            if($role->hasPermission($permission))
                return true;
        }
        return false;
    }
1122569
public function hidden($hidden = [], $override = false)
    {
        $this->hidden = $override ? $hidden : array_merge($this->hidden, $hidden);

        return $this;
    }
650694
public function created(Permission $permission)
    {
        $superAdminRole = RoleRepository::GET_SUPER_ADMIN();
        if ($superAdminRole) {
            $superAdminRole->givePermissionTo($permission);
        }
        //
        if ($permission->is_default_action === false) {
            $this->createLanguageTerm($permission->model, $permission->action);
        }
    }
104260
public function publish($override = false)
    {
        // publish files
        foreach ($this->publishAssets['files'] as $from => $to) {
            $this->publishFile($from, $to, $override);
        }

        // publish directory
        foreach ($this->publishAssets['dirs'] as $fromDir => $toDir) {
            $this->publishDir($fromDir, $toDir, $override);
        }

        // no define asset to publish, will publish source-path to publish-path
        if (!$this->hasAssetToPublish()) {
            $this->publishDir($this->sourcePath, $this->publishPath, $override);
        }

        return $this;
    }
831502
public function addPermission(AbstractCompanyUserPermission $permission): bool
    {
        if (!empty($this->permissions)) {
            $this->permissions = array_merge($this->permissions, [$permission]);
        } else {
            $this->permissions = [$permission];
        }
        return $this->updateModel();
    }
459309
public function hasCallerPermission(Caller $caller, Permission $permission)
    {
        // Iterate over each permission from the user and check if the permission is in the array.
        foreach ($this->getCallerPermissions($caller) as $callerPermission) {
            // If a matching permission was found, immediately break the sequence and return true.
            if ($callerPermission->matchesPermission($permission)) {
                return true;
            }
        }

        return false;
    }
548803
public function addPermission(Permission $permission)
    {
        try {
            $this->saveEntity($permission);
        } catch (UniqueConstraintViolationException $e) {
            throw new NotUniqueException('Permission with name ' . $permission->getName() . ' already created');
        }
    }
1096489
public function setHeaders($headers, $override = true)
    {
        if ($override == false) {
            $this->headers = array_merge($headers, $this->headers);
        } else {
            $this->headers = $headers;
        }

        return $this;
    }
534967
public function updated(Permission $permission)
    {
        $original = $permission->getOriginal();
        if (count($original)) {
            $oldPermission = new Permission($original);
            if ($permission->name != $oldPermission->name) {
                $this->updateLanguageTerm($oldPermission, $permission);
            }
        } elseif ($permission->is_default_action === false) {
            $this->createLanguageTerm($permission->model, $permission->action);
        }
    }
48025
public function addPermissionForUser($user, ...$permission)
    {
        $params = [];

        $params[] = $user;
        foreach ($permission as $perm) {
            $params[] = $perm;
        }

        return $this->addPolicy(...$params);
    }
394441
protected function storePermission(Permission $permission)
    {
        // Don't re-store the permission if it already exists.
        if (! $this->hasPermission($permission)) {
            $this->getDriver()->storeRolePermission($this->role, $permission);
        }
    }
698166
public function addPermission(Permission $permission)
    {
        if (!$permission->permission_id) {
            throw new ValidationError("Permission has invalid state");
        }
        if (!in_array($permission, $this->permissions)) {
            $this->permissions[] = $permission;
            return true;
        }
        return false;
    }
579498
private function createRules(Permission $permission): void
	{
		/* @var $rule Acl */
		foreach ($this->orm->acl->findAll() as $rule) {
			if ($rule->allowed) {
				$permission->allow($rule->role->name, $rule->resource->resource, $rule->privilege);
			} else {
				$permission->deny($rule->role->name, $rule->resource->resource, $rule->privilege);
			}
		}
	}
1337775
protected function hasPermission(string $permission, bool $return = false)
    {
        $auth = $this->getContext()->getAuthentication();
        $user = $auth->getUser();
        $acl = $this->getContext()->getAccessControlList();

        if (!$acl->hasAccess($user, $permission)) {

            if ($return) {
                return false;
            }else{
                throw HttpException::forbidden('The current user has no permission to this action');
            }
        }

        return true;
    }
424444
public function hasPermission($permission)
    {
        $permissions = $this->permissions;
        foreach ($permissions as $permission_obj)
            if ($this->checkPermission($permission, $permission_obj))
                return true;

        return false;
    }
319523
public function create(bool $override): bool {
        if ($this->isFile() && !$override) return false;
        $handle = @fopen($this->path, 'w');
        if (false === $handle) return false;
        fclose($handle);
        return true;
    }