src/Router.php
protected function parseUrl($request, $routingParse = null)
    {
        $vars = null;
        $v = [];

        if ($routingParse === null) {
            $routingParse = $this->routeMapParse;
        }

        $pos = strpos($request, '?task=');
        if ($pos !== false) {
            $request = substr_replace($request, '/?task=', $pos, strlen('?task='));
        }

        $request = str_replace('?', '&', $request);

        foreach ($routingParse as $k => $v) {
            if (!is_array($v)) {
                continue;
            }

            preg_match_all('!\[(.+?)\]!i', $v[0], $expression_);
            $expressionMatch = preg_replace_callback(
                '!\[(.+?)\]!i',
                function ($m) use ($k) {
                    return $this->transformParam($m[1], $k);
                },
                $v[0]
            );

            if (preg_match_all('!' . $expressionMatch . '!i', $request, $expression__)) {
                $args = [];

                if (isset($v['args'])) {
                    $args = $v['args'];
                }

                foreach ($expression__ as $k_ => $v_) {
                    foreach ($v_ as $kkk => $vvv) {
                        if (!isset($expression_[1][$k_ - 1])) {
                            $expression_[1][$k_ - 1] = null;
                        }

                        if ($kkk > 0) {
                            $expression[] = [$expression_[1][$k_ - 1] . '_' . $kkk, $vvv];
                        } else {
                            $expression[] = [$expression_[1][$k_ - 1], $vvv];
                        }
                    }
                }
                unset($expression[0]);
                $iCount = count($expression__[0]);

                if ($iCount > 1) {
                    for ($i = 0; $i < $iCount; $i++) {
                        if ($i > 0) {
                            $vars .= '&' . preg_replace('!\[(.+?)\]!i', '[$1_' . $i . ']', $v[1]);
                        } else {
                            $vars = '&' . $v[1];
                        }
                    }
                } else {
                    $vars = '&' . $v[1];
                }

                foreach ($expression as $v_) {
                    if (!isset($v['_' . $v_[0]])) {
                        $v['_' . $v_[0]] = null;
                    }

                    if (!is_array($v['_' . $v_[0]])) {
                        foreach ($args as $key => $value) {
                            $args[$key] = str_replace('[' . $v_[0] . ']', $v_[1], $args[$key]);
                        }
                        $vars = str_replace('[' . $v_[0] . ']', $v_[1], $vars);
                    } else {
                        $vars = $vars . $this->parseUrl($v_[1], [$v['_' . $v_[0]]])['sVars'];
                    }
                }
                $this->parseArgs = $args;
                break;
            }
        }


        if (isset($this->app->debug)) {
            $this->app->debug->addHeader(['X-DF-Debug-sVars' => $vars]);
        }

        return ['v' => $v, 'sVars' => $vars];
    }
protected function parseUrl($request, $routingParse = null)
    {
        $vars = null;
        $v = [];

        if ($routingParse === null) {
            $routingParse = $this->routeMapParse;
        }

        $pos = strpos($request, '?task=');
        if ($pos !== false) {
            $request = substr_replace($request, '/?task=', $pos, strlen('?task='));
        }

        $request = str_replace('?', '&', $request);

        foreach ($routingParse as $k => $v) {
            if (!is_array($v)) {
                continue;
            }

            preg_match_all('!\[(.+?)\]!i', $v[0], $expression_);
            $expressionMatch = preg_replace_callback(
                '!\[(.+?)\]!i',
                function ($m) use ($k) {
                    return $this->transformParam($m[1], $k);
                },
                $v[0]
            );

            if (preg_match_all('!' . $expressionMatch . '!i', $request, $expression__)) {
                $args = [];

                if (isset($v['args'])) {
                    $args = $v['args'];
                }

                foreach ($expression__ as $k_ => $v_) {
                    foreach ($v_ as $kkk => $vvv) {
                        if (!isset($expression_[1][$k_ - 1])) {
                            $expression_[1][$k_ - 1] = null;
                        }

                        if ($kkk > 0) {
                            $expression[] = [$expression_[1][$k_ - 1] . '_' . $kkk, $vvv];
                        } else {
                            $expression[] = [$expression_[1][$k_ - 1], $vvv];
                        }
                    }
                }
                unset($expression[0]);
                $iCount = count($expression__[0]);

                if ($iCount > 1) {
                    for ($i = 0; $i < $iCount; $i++) {
                        if ($i > 0) {
                            $vars .= '&' . preg_replace('!\[(.+?)\]!i', '[$1_' . $i . ']', $v[1]);
                        } else {
                            $vars = '&' . $v[1];
                        }
                    }
                } else {
                    $vars = '&' . $v[1];
                }

                foreach ($expression as $v_) {
                    if (!isset($v['_' . $v_[0]])) {
                        $v['_' . $v_[0]] = null;
                    }

                    if (!is_array($v['_' . $v_[0]])) {
                        foreach ($args as $key => $value) {
                            $args[$key] = str_replace('[' . $v_[0] . ']', $v_[1], $args[$key]);
                        }
                        $vars = str_replace('[' . $v_[0] . ']', $v_[1], $vars);
                    } else {
                        $vars = $vars . $this->parseUrl($v_[1], [$v['_' . $v_[0]]])['sVars'];
                    }
                }
                $this->parseArgs = $args;
                break;
            }
        }


        if (isset($this->app->debug)) {
            $this->app->debug->addHeader(['X-DF-Debug-sVars' => $vars]);
        }

        return ['v' => $v, 'sVars' => $vars];
    }
protected function parseUrl ( $ request , $ routingParse = null ) { $ vars = null ; $ v = [ ] ; if ( $ routingParse === null ) { $ routingParse = $ this -> routeMapParse ; } $ pos = strpos ( $ request , '?task=' ) ; if ( $ pos !== false ) { $ request = substr_replace ( $ request , '/?task=' , $ pos , strlen ( '?task=' ) ) ; } $ request = str_replace ( '?' , '&' , $ request ) ; foreach ( $ routingParse as $ k => $ v ) { if ( ! is_array ( $ v ) ) { continue ; } preg_match_all ( '!\[(.+?)\]!i' , $ v [ 0 ] , $ expression_ ) ; $ expressionMatch = preg_replace_callback ( '!\[(.+?)\]!i' , function ( $ m ) use ( $ k ) { return $ this -> transformParam ( $ m [ 1 ] , $ k ) ; } , $ v [ 0 ] ) ; if ( preg_match_all ( '!' . $ expressionMatch . '!i' , $ request , $ expression__ ) ) { $ args = [ ] ; if ( isset ( $ v [ 'args' ] ) ) { $ args = $ v [ 'args' ] ; } foreach ( $ expression__ as $ k_ => $ v_ ) { foreach ( $ v_ as $ kkk => $ vvv ) { if ( ! isset ( $ expression_ [ 1 ] [ $ k_ - 1 ] ) ) { $ expression_ [ 1 ] [ $ k_ - 1 ] = null ; } if ( $ kkk > 0 ) { $ expression [ ] = [ $ expression_ [ 1 ] [ $ k_ - 1 ] . '_' . $ kkk , $ vvv ] ; } else { $ expression [ ] = [ $ expression_ [ 1 ] [ $ k_ - 1 ] , $ vvv ] ; } } } unset ( $ expression [ 0 ] ) ; $ iCount = count ( $ expression__ [ 0 ] ) ; if ( $ iCount > 1 ) { for ( $ i = 0 ; $ i < $ iCount ; $ i ++ ) { if ( $ i > 0 ) { $ vars .= '&' . preg_replace ( '!\[(.+?)\]!i' , '[$1_' . $ i . ']' , $ v [ 1 ] ) ; } else { $ vars = '&' . $ v [ 1 ] ; } } } else { $ vars = '&' . $ v [ 1 ] ; } foreach ( $ expression as $ v_ ) { if ( ! isset ( $ v [ '_' . $ v_ [ 0 ] ] ) ) { $ v [ '_' . $ v_ [ 0 ] ] = null ; } if ( ! is_array ( $ v [ '_' . $ v_ [ 0 ] ] ) ) { foreach ( $ args as $ key => $ value ) { $ args [ $ key ] = str_replace ( '[' . $ v_ [ 0 ] . ']' , $ v_ [ 1 ] , $ args [ $ key ] ) ; } $ vars = str_replace ( '[' . $ v_ [ 0 ] . ']' , $ v_ [ 1 ] , $ vars ) ; } else { $ vars = $ vars . $ this -> parseUrl ( $ v_ [ 1 ] , [ $ v [ '_' . $ v_ [ 0 ] ] ] ) [ 'sVars' ] ; } } $ this -> parseArgs = $ args ; break ; } } if ( isset ( $ this -> app -> debug ) ) { $ this -> app -> debug -> addHeader ( [ 'X-DF-Debug-sVars' => $ vars ] ) ; } return [ 'v' => $ v , 'sVars' => $ vars ] ; }
Match given request

@param string      $request
@param string|null $routingParse

@return string|array
Match given request