/** * Formats the given SPARQL string. * Note that there have to be spaces before and after brackets and dots. * * @param string $sparql * @return string */ public function format($sparql) { $this->formattedParts = array(); $this->indentationLevel = 0; $this->replacements = array(); $regexHelper = new RegexHelper(); $sparql = $regexHelper->escapeSequences($sparql, $this->replacements); foreach ($this->split($sparql) as $part) { if (!empty($this->formattedParts)) { $this->before($part); } $this->indentation($part); $this->append($part); $this->after($part); } $this->trimEnd(); $this->formattedParts[] = "\n"; return strtr(implode($this->formattedParts), $this->replacements); }
/** * Extracts distinct values from the array that don't contain whitespace. * * @param array $array The array to extract the values from * @return \Puzzlout\Framework\Helpers\ArrayExtractionHelper The extrator instance. */ public function ExtractDistinctValues($array) { foreach ($array as $key => $value) { $valueIsArray = is_array($value); $valueIsAlreadyExtracted = in_array($value, $this->List); $keyIsExtracted = in_array($key, $this->List); if (!$valueIsArray && !$valueIsAlreadyExtracted && !RegexHelper::Init($value)->StringContainsWhiteSpace()) { array_push($this->List, $value); } if (!$keyIsExtracted && is_string($key) && !RegexHelper::Init($key)->StringContainsWhiteSpace()) { array_push($this->List, $key); } if ($valueIsArray) { $this->ExtractDistinctValues($value); } } return $this; }
/** * @desc Returns the regex matching the requested url form * @param int $protocol REGEX_MULTIPLICITY_OPTION for the protocol sub-regex * @param int $user REGEX_MULTIPLICITY_OPTION for the user:password@ sub-regex * @param int $domain REGEX_MULTIPLICITY_OPTION for the domain sub-regex * @param int $folders REGEX_MULTIPLICITY_OPTION for the folders sub-regex * @param int $file REGEX_MULTIPLICITY_OPTION for the file sub-regex * @param int $args REGEX_MULTIPLICITY_OPTION for the arguments sub-regex * @param int $anchor REGEX_MULTIPLICITY_OPTION for the anchor sub-regex * @param bool $forbid_js true if you want to forbid javascript uses in urls * @return the regex matching the requested url form * @see RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL * @see REGEX_MULTIPLICITY_NEEDED * @see RegexHelper::REGEX_MULTIPLICITY_AT_LEAST_ONE * @see RegexHelper::REGEX_MULTIPLICITY_ALL * @see RegexHelper::REGEX_MULTIPLICITY_NOT_USED */ public static function get_wellformness_regex($protocol = RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL, $user = RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL, $domain = RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL, $folders = RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL, $file = RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL, $args = RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL, $anchor = RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL, $forbid_js = true) { if ($forbid_js) { $protocol_regex_secured = self::FORBID_JS_REGEX . self::PROTOCOL_REGEX; } else { $protocol_regex_secured = self::PROTOCOL_REGEX; } $regex = RegexHelper::set_subregex_multiplicity($protocol_regex_secured, $protocol) . RegexHelper::set_subregex_multiplicity(self::USER_REGEX, $user) . RegexHelper::set_subregex_multiplicity(self::DOMAIN_REGEX, $domain) . RegexHelper::set_subregex_multiplicity(self::FOLDERS_REGEX, $folders) . RegexHelper::set_subregex_multiplicity(self::FILE_REGEX, $file); if ($anchor == RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL) { $regex .= RegexHelper::set_subregex_multiplicity(self::ANCHOR_REGEX, RegexHelper::REGEX_MULTIPLICITY_OPTIONNAL); } $regex .= RegexHelper::set_subregex_multiplicity(self::ARGS_REGEX, $args) . RegexHelper::set_subregex_multiplicity(self::ANCHOR_REGEX, $anchor); return $regex; }