Allow/disallow self URIs for a given directive

@param string $directive
@param bool $allow
@return self
@throws \Exception
168299
public function setSelfAllowed(string $directive = '', bool $allow = false): self
    {
        if (!\in_array($directive, self::$directives)) {
            throw new \Exception('Directive ' . $directive . ' does not exist');
        }
        $this->policies[$directive]['self'] = $allow;
        return $this;
    }
438546
protected function extractDirectives($directive, $content)
    {
        $pattern = '/{{'.$directive.'\(?([\w\.]*)\)?}}/';
        preg_match_all($pattern, $content, $result);

        return $result;
    }
326772
function $permission() {
    'ngInject';

    var defaultOnAuthorizedMethod = 'showElement';
    var defaultOnUnauthorizedMethod = 'hideElement';
    var suppressUndefinedPermissionWarning = false;

    /**
     * Methods allowing to alter default directive onAuthorized behaviour in permission directive
     * @methodOf permission.permissionProvider
     *
     * @param onAuthorizedMethod {String} One of permission.PermPermissionStrategies method names
     */
    this.setDefaultOnAuthorizedMethod = function (onAuthorizedMethod) { // jshint ignore:line
      defaultOnAuthorizedMethod = onAuthorizedMethod;
    };

    /**
     * Methods allowing to alter default directive onUnauthorized behaviour in permission directive
     * @methodOf permission.permissionProvider
     *
     * @param onUnauthorizedMethod {String} One of permission.PermPermissionStrategies method names
     */
    this.setDefaultOnUnauthorizedMethod = function (onUnauthorizedMethod) { // jshint ignore:line
      defaultOnUnauthorizedMethod = onUnauthorizedMethod;
    };


    /**
     * When set to true hides permission warning for undefined roles and permissions
     * @methodOf permission.permissionProvider
     *
     * @param value {Boolean}
     */
    this.suppressUndefinedPermissionWarning = function (value) { // jshint ignore:line
      suppressUndefinedPermissionWarning = value;
    };


    this.$get = function () { // jshint ignore:line
      return {
        defaultOnAuthorizedMethod: defaultOnAuthorizedMethod,
        defaultOnUnauthorizedMethod: defaultOnUnauthorizedMethod,
        suppressUndefinedPermissionWarning: suppressUndefinedPermissionWarning
      };
    };
  }
499791
function allowMapDownload($allow = true, $multicall = false)
    {
        if (!is_bool($allow)) {
            throw new InvalidArgumentException('allow = ' . print_r($allow, true));
        }

        return $this->execute(ucfirst(__FUNCTION__), array($allow), $multicall);
    }
1270501
public function hash(
        string $directive = 'script-src',
        string $script = '',
        string $algorithm = 'sha384'
    ): self {
        $ruleKeys = \array_keys($this->policies);
        if (\in_array($directive, $ruleKeys)) {
            $this->policies[$directive]['hashes'] []= [
                $algorithm => Base64::encode(
                    \hash($algorithm, $script, true)
                )
            ];
        }
        return $this;
    }
141446
public function chmod($mode, $filename)
    {
        $result = @ftp_chmod($this->connection, $mode, $filename);
        
        if ($result === false) {
            throw new Exception('Unable to change permissions');
        }

        return $this;
    }
452087
public function withScheme($scheme): UriInterface
    {
        $scheme = $this->filterScheme($scheme);

        $clone = clone $this;
        $clone->scheme = $scheme;

        return $clone;
    }
180884
public function limit($limit)
    {
        if(!empty($limit))
            $this->selectParams[self::LIMIT] = $limit;
        else
            unset($this->selectParams[self::LIMIT]);
        return $this;
    }
347074
private function check($directive, $uri)
    {
        $uriParser = new UriParser($uri);
        $uri = $uriParser->convertToFull($this->base);
        if ($this->base !== $uriParser->base()) {
            throw new \InvalidArgumentException('URI belongs to a different robots.txt');
        }
        if (($result = $this->checkOverride($uri)) !== false) {
            return $directive === $result;
        }
        // Path check
        return $this->checkPath($directive, $uri);
    }
515103
protected function lexDirective(bool $isConst = false): DirectiveNode
    {
        $start = $this->lexer->getToken();

        $this->expect(TokenKindEnum::AT);

        return new DirectiveNode(
            $this->lexName(),
            $this->lexArguments($isConst),
            $this->createLocation($start)
        );
    }
439613
public function includeInactive($enable = true)
    {
        $this->includeInactive = (bool) $enable;

        $this->refreshSettingDependentCriteria();

        return $this;
    }
526451
private function checkPath($directive, $uri)
    {
        $resultLength = 0;
        $resultDirective = self::DIRECTIVE_ALLOW;
        foreach ([
                     self::DIRECTIVE_DISALLOW => $this->handler->disallow->client()->hasPath($uri),
                     self::DIRECTIVE_ALLOW => $this->handler->allow->client()->hasPath($uri),
                 ] as $currentDirective => $currentLength) {
            if ($currentLength >= $resultLength) {
                $resultLength = $currentLength;
                $resultDirective = $currentDirective;
            }
        }
        return $directive === $resultDirective;
    }
1175624
public function setParentDirective(Directive $parentDirective)
    {
        $this->parentDirective = $parentDirective;

        if ($parentDirective->getChildScope() !== $this) {
            $parentDirective->setChildScope($this);
        }

        return $this;
    }
278883
protected function removeScope( Node$scope ):self
	{
		if( $scope!==array_shift($this->scopes) ){
			$this->throw('Scope nesting error');
		};

		return $this;
	}
809748
protected static function compileDirective(string $directive, $policies): string
    {
        // handle special directive first
        switch ($directive) {
            // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/plugin-types
            case 'plugin-types':
                return empty($policies) ? '' : sprintf('%s %s', $directive, implode(' ', $policies));

            // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/require-sri-for
            // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/sandbox
            case 'require-sri-for':
            case 'sandbox':
                return empty($policies) ? '' : sprintf('%s %s', $directive, $policies);
        }

        // when policies is empty, we assume that user disallow this directive
        if (empty($policies)) {
            return sprintf("%s 'none'", $directive);
        }

        $ret = [$directive];

        // keyword source, https://www.w3.org/TR/CSP/#grammardef-keyword-source, https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
        foreach (['self', 'unsafe-inline', 'unsafe-eval', 'strict-dynamic', 'unsafe-hashed-attributes', 'report-sample'] as $keyword) {
            if (! empty($policies[$keyword])) {
                $ret[] = sprintf("'%s'", $keyword);
            }
        }

        if (! empty($policies['allow'])) {
            foreach ($policies['allow'] as $url) {
                // removes illegal URL characters
                if (false !== ($url = filter_var($url, FILTER_SANITIZE_URL))) {
                    $ret[] = $url;
                }
            }
        }

        if (! empty($policies['hashes'])) {
            foreach ($policies['hashes'] as $algo => $hashes) {
                // skip not support algorithm, https://www.w3.org/TR/CSP/#grammardef-hash-source
                if (! in_array($algo, ['sha256', 'sha384', 'sha512'])) {
                    continue;
                }

                foreach ($hashes as $value) {
                    // skip invalid value
                    if (! self::isBase64Valid($value)) {
                        continue;
                    }

                    $ret[] = sprintf("'%s-%s'", $algo, $value);
                }
            }
        }

        if (! empty($policies['nonces'])) {
            foreach ($policies['nonces'] as $nonce) {
                // skip invalid value, https://www.w3.org/TR/CSP/#grammardef-nonce-source
                if (! self::isBase64Valid($nonce)) {
                    continue;
                }

                $ret[] = sprintf("'nonce-%s'", $nonce);
            }
        }

        if (! empty($policies['schemes'])) {
            foreach ($policies['schemes'] as $scheme) {
                $ret[] = sprintf('%s', $scheme);
            }
        }

        return implode(' ', $ret);
    }
232011
public function force_ansi($enable = true)
    {
        if ($enable) {
            $this->climate->forceAnsiOn();
        } else {
            $this->climate->forceAnsiOff();
        }

        return $this;
    }
570922
public function removeDirective($name)
    {
        $name = strtolower(trim($name));
        unset($this->directives[$name]);
        return $this;
    }