replaceSegments

@param string $route
@param array  &$data

@return  mixed|string
964661
protected static function replaceAllSegments($route, &$data)
    {
        preg_match_all(chr(1) . '\(([a-z][a-zA-Z0-9_]*)\)' . chr(1), $route, $matches, PREG_SET_ORDER);

        foreach ($matches as $match) {
            if (isset($data[$match[1]])) {
                $route = str_replace($match[0], $data[$match[1]], $route);

                unset($data[$match[1]]);
            }
        }

        $queries = http_build_query($data);

        if ($queries) {
            $route = rtrim($route, '/') . '?' . $queries;
        }

        return $route;
    }
970717
protected static function dynamic($route)
    {
        $parms = [];
        $param = '';
        $open = false;
        //
        for ($i = 0; $i < Strings::length($route); $i++) {
            if ($open && $route[$i] != '}') {
                $param .= $route[$i];
            }
            //
            if ($route[$i] == '{' && !$open) {
                $open = true;
            } //
            elseif ($route[$i] == '}' && $open) {
                $open = !true;
                $parms[] = $param;
                $param = '';
            }
        }
        //
        return $parms;
    }
1369446
protected function replaceRouteParameters($path, array &$parameters)
    {
        if (count($parameters) > 0) {
            $path = preg_replace_sub(
                '/\{.*?\}/', $parameters, $this->replaceNamedParameters($path, $parameters)
            );
        }

        return trim(preg_replace('/\{.*?\?\}/', '', $path), '/');
    }
1166055
private static function removeDotSegments(string $path)
    {
        $result = '';

        while (!\in_array($path, ['', '.', '..'], true)) {
            if ('.' === $path[0] && (0 === strpos($path, $p = '../') || 0 === strpos($path, $p = './'))) {
                $path = substr($path, \strlen($p));
            } elseif ('/.' === $path || 0 === strpos($path, '/./')) {
                $path = substr_replace($path, '/', 0, 3);
            } elseif ('/..' === $path || 0 === strpos($path, '/../')) {
                $i = strrpos($result, '/');
                $result = $i ? substr($result, 0, $i) : '';
                $path = substr_replace($path, '/', 0, 4);
            } else {
                $i = strpos($path, '/', 1) ?: \strlen($path);
                $result .= substr($path, 0, $i);
                $path = substr($path, $i);
            }
        }

        return $result;
    }
375859
function formatToArrayDataTables($route = null,array $parameters = array()) {
        $results = $this->getCurrentPageResults()->getArrayCopy();
        $data = array(
            'draw' => $this->draw,
            'recordsTotal' => $this->getNbResults(),
            'recordsFiltered' => $this->getNbResults(),
            'data' => $results,
            '_links' => $this->getLinks($route,$parameters),
        );
        return $data;
    }
456319
private static function replace(string $text, Array $data = null): string {
    if (!empty($text) && count($data)) {
      if ($metaText = (new ReplaceText())->replace($text, $data)) {
        $text = $metaText;
      }
    }
    return $text;
  }
1018995
protected static function replaceWildCards($route, &$data)
    {
        preg_match_all(chr(1) . '\(\*([a-z][a-zA-Z0-9_]*)\)' . chr(1), $route, $matches, PREG_SET_ORDER);

        if (!$matches) {
            return $route;
        }

        foreach ($matches as $match) {
            if (isset($data[$match[1]])) {
                $route = str_replace($match[0], implode('/', (array) $data[$match[1]]), $route);

                unset($data[$match[1]]);
            }
        }

        return $route;
    }
203367
static public function getRoutePatternParts( Route $route ){
		$parts	= array();
		foreach( explode( "/", $route->getPattern() ) as $part ){
			$optional	= FALSE;
			$argument	= FALSE;
			if( preg_match( "@\(:.+\)@", $part ) ){													//  optional argument found
				$part		= substr( $part, 1, -1 );												//  cut argument key
				$optional	= TRUE;																	//  note that is optional
			}
			if( substr( $part, 0, 1 ) === ":" ){													//  argument found
				$part		= substr( $part, 1 );													//  cut argument key
				$argument	= TRUE;																	//  note that is argument
			}
			$parts[]	= (object) array(															//  prepare route pattern part object
				'key'		=> $part,
				'optional'	=> $optional,
				'argument'	=> $argument,
			);
		}
		return $parts;
	}
184353
private function prepareRouteRegexp(string $route): string
    {
        if (!array_key_exists($route, self::$parsed_regexp)) {
            self::$parsed_regexp[$route] = preg_replace(array_keys($this->regexp_map), array_values($this->regexp_map), $route);
        }
        return self::$parsed_regexp[$route];
    }
363536
protected function _compile_regex($route)
    {
        $pattern = '`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`';

        if ( preg_match_all($pattern, $route, $matches, PREG_SET_ORDER) ) {
            $match_types = array(
                'i'  => '[0-9]++',
                'a'  => '[0-9A-Za-z]++',
                'h'  => '[0-9A-Fa-f]++',
                '*'  => '.+?',
                ''   => '[^/]++'
            );
            foreach ( $matches as $match ) {
                list($block, $pre, $type, $param, $optional) = $match;

                if ( isset($match_types[$type]) ) {
                    $type = $match_types[$type];
                }
                if ( $param ) {
                    $param = "?<{$param}>";
                }
                if ( $optional ) {
                    $optional = '?';
                }

                $replaced = "(?:{$pre}({$param}{$type})){$optional}";
                $route = str_replace($block, $replaced, $route);
            }
        }
        if ( substr($route, strlen($route) - 1) != '/' ) {
            $route .= '/?';
        }
        return "`^{$route}$`";
    }
1297815
private function loadAndParseRoute($route)
    {
         // Get meta into view structure
         $meta = $this->getMetaForRoute($route);
         unset($meta["__toc__"]);
         unset($meta["views"]);

        // Get filtered content from route
        list($routeIndex, , $filtered) =
            $this->mapRoute2Content($route);

        // Merge frontmatter with meta
        // then merge frontmatter base into views main
        $filtered->frontmatter = array_merge_recursive_distinct(
            $meta,
            $filtered->frontmatter
        );

        // Do phase 2 processing to get new filtered content
        // (and updated frontmatter)
        $this->processContentPhaseTwo($filtered);

        // Create complete frontmatter, inluding content
        $filtered->frontmatter["data"]["content"] = isset($filtered->text)
            ? $filtered->text
            : null;

        // Load additional content for view, based on data-meta
        $view = ["main" => $filtered->frontmatter];
        $this->loadAdditionalContent($view, $route, $routeIndex);

        return $view["main"];
    }
36048
public static function to($path, array $data = null )
	{
		//compose query string if data was set
		($data !== null) ? self::with($data) : '';

		//compose full url
		$path = (self::$query_string === null) ?  Url::link($path) : Url::link($path) . '?' . self::$query_string;

		//redirect to path
		header('Location: ' . $path);

		//stop any further html output
		exit();

	}
1323436
public static function replace($uri, $parameters = [])
    {
        $parameters = (array) $parameters;

        $uri = static::replaceRouteParameters($uri, $parameters);
        $uri = str_replace('//', '/', $uri);

        return $uri;
    }
79787
protected function getRouteApiParts($route)
    {
        $name = explode('/', $route->getPattern());

        $parts = array(
            'exposed' => false
        );

        // if the name has more than one string pattern
        if (count($name) > 2){
            // get the method name
            $method = array_pop($name);

            // upcase the namespace names
            array_walk($name, function(&$n){
                $n = ucfirst($n);
            });

            $path = implode('', $name);

            $parts = array(
                'path' => $path,
                'exposed' => true,
                'name' => $method,
                'len' => 1
            );

            if ($route->isFormDirect()){
                $parts['formHandler'] = true;
            }

        }

        return $parts;
    }
751900
public function pageTitle($route = null, array  $replacements = []) {
        if(!$route) {
            $route = \Route::currentRouteName();
        }

        return $this->applyReplacement(Arr::get(self::pageTitleValues(), $route, 'title'), $replacements);
    }
1242534
protected function compile($route)
    {
        if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
            foreach ($matches as $match) {
                list($block, $pre, $type, $param, $optional) = $match;

                if (isset($this->_match_types[$type])) {
                    $type = $this->_match_types[$type];
                }
                if ($pre === '.') {
                    $pre = '\.';
                }

                //Older versions of PCRE require the 'P' in (?P<named>)
                $pattern = '(?:'
                    .($pre !== '' ? $pre : null)
                    .'('
                    .($param !== '' ? "?P<$param>" : null)
                    .$type
                    .'))'
                    .($optional !== '' ? '?' : null);

                $route = str_replace($block, $pattern, $route);
            }
        }

        return "`^$route$`u";
    }
411308
public static function replaceRelativePathElements($path)
    {
        $pathSegments = explode('/', $path);
        $absolutePath = '';
        foreach ($pathSegments as $pathSegment) {
            switch ($pathSegment) {
                case '.':
                    continue 2;
                break;
                case '..':
                    $absolutePath = NodePaths::getParentPath($absolutePath);
                break;
                default:
                    $absolutePath = NodePaths::addNodePathSegment($absolutePath, $pathSegment);
                break;
            }
        }

        return $absolutePath;
    }