Converts a routing string into parameters for the defaultCallable.

@param array $segments Segments of the controller,method,parameters to open
@param string @route   The route which was matched
@return void
557495
protected function routeDefault($segments = array(), $route)
    {
        // If we don't have any segments left - try the default controller;
        // WARNING: Directories get shifted out of the segments array!
        if (empty($segments))
        {
            $segments[0] = $this->config->routing->default_controller;
        }

        if ($this->config->routing->translate_uri_dashes === true)
        {
            $segments[0] = str_replace('-', '_', $segments[0]);
            if (isset($segments[1]))
            {
                $segments[1] = str_replace('-', '_', $segments[1]);
            }
        }

        // Prepare the values for loading
        $controller = $segments[0];
        $function = (isset($segments[1]) ? $segments[1] : $this->config->routing->default_function);

        // And prepare the Router URI
        array_unshift($segments, null);
        unset($segments[0]);
        $this->uri->rsegments = $segments;

        // Now create a matches array
        $matches = array(
                'controller' => $controller,
                'function' => $function,
                'parameters' => array_slice($this->uri->rsegments, 2)
            );

        // And finally load the callable
        $this->callable = array('\FuzeWorks\Router', 'defaultCallable');
        $this->loadCallable($matches, $route);
    }
70627
protected function parseRoutes($routes)
	{
		$tree = [];

		foreach ($routes as $Route) {
			$node = &$tree;
			$routeSegments = $this->normalize($Route->route);

			foreach ($routeSegments as $segment) {
				if (!isset($node[$segment["use"]])) {
					$node[$segment["use"]] = [
						"name" => $segment["name"],
						"routeName" => $Route->name
					];
				}
				$node = &$node[$segment["use"]];
			}
			$Route->segments = $routeSegments;
			//node exec can exists only if a route is already added.
			//This happens when a route is added more than once with different methods.
			$node["exec"]["method"][$Route->method] = $Route;
		}

		return $tree;
	}
888977
protected function _routeMatch($matches)
    {
        if (isset($this->_tmpMatches[$matches[1]])) {
            return $this->_tmpMatches[$matches[1]];
        }
        if (isset($this->_tmpDefault[$this->_tmpKey])) {
            return $this->_tmpDefault[$this->_tmpKey];
        }
        throw new \Mmi\Mvc\MvcException('Router failed due to invalid route definition - no default param for key: ' . $this->_tmpKey);
    }
855181
public static function url($segments, $options = array())
    {
        $request = Router::getInstance()->request;

        $options['X-App-Id'] = Context::getKey()->app_id;
        $options['X-App-Key'] = Context::getKey()->key;

        $segments .= '?' . http_build_query($options);

        return $request->getUrl() . $request->getScriptName() . '/' . $segments;
    }
1124515
public static function all( $routes ) 
	{

		/* Call all functions that are to be executed before routing */
		foreach( self::$beforeFuncs as $beforeFunc ) {
			if( $beforeFunc[1] ) {
				call_user_func_array( $beforeFunc[0] , $beforeFunc[1] );
			} else {
				call_user_func( $beforeFunc[0] );
			}
		}

		self::$routes = $routes;
		$method = strtolower($_SERVER['REQUEST_METHOD']);
		$path = '/';
		$handler = null;
		$matched = array();
		if ( !empty ( $_SERVER['PATH_INFO'] ) ) {
			$path = $_SERVER['PATH_INFO'];
		} else if ( !empty ( $_SERVER['REQUEST_URI'] ) ) {
            $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
		}

		if ( isset($routes[$path] ) ) {
			if( is_array( $routes[$path] ) ) {
				$handler = $routes[$path][0];
			} else {
				$handler = $routes[$path];
			}
		} else if ( $routes ) {
			
			$regex = array(
				'/{i}/',
				'/{s}/',
				'/{a}/'
				);

			$replacements = array(
				'([\d]+)'	,
				'([a-zA-Z]+)',
				'([\w-]+)'
				);

			foreach ( $routes as $routePath => $routeDesc ){
				$routePath = preg_replace( $regex, $replacements, $routePath );
				if( preg_match( '#^/?' . $routePath . '/?$#', $path, $matches ) ){
					if( is_array( $routeDesc ) ) {
						$handler = $routeDesc[0];
						if( isset( $routeDesc[2] )) {
							$middleware = $routeDesc[2];
						}
					}
					else 
						$handler = $routeDesc;
					$matched = $matches;
					break;
				}
			}
		}
		unset( $matched[0] );

		if( isset($middleware) ){
			$newMatched = self::callFunction( $middleware, $matched, $method );
			/* If new wildcard param are there pass them to main handler */
			if( $newMatched ) { 
				self::callFunction( $handler, $newMatched, $method );
			} else {
				self::callFunction( $handler, $matched, $method );
			}
		} else {
			self::callFunction( $handler, $matched, $method );
		}

		/* Call all the function that are to be executed after routing */
		foreach( self::$afterFuncs as $afterFunc )
			if( $afterFunc[1] ) {
				call_user_func_array( $afterFunc[0] , $afterFunc[1] );
			} else {
				call_user_func( $afterFunc[0] );
			}
	}
601100
private static function bind($url, $controller, array $definition, array $where)
    {
        $path = '/'.trim($url.$definition['url'], '/');

        // Launch of the route mapping method.
        $route = static::$application->{$definition['method']}(
            $path,
            sprintf("%s@%s", $controller, $definition['call'])
        );

        // Add name on the road
        $name = str_replace('/', '.', $url).'.'.$definition['call'];

        $route->name($name);

        // Association of defined criteria
        if (isset($where[$definition['call']])) {
            $route->where((array) $where[$definition['call']]);
        } else {
            $route->where((array) $where);
        }
    }
711839
protected function buildUrl(array $segments = [])
    {
        //Get the base URL and add a ?
        $url = $this->apiBase.'?';

        if (isset($this->apiEnding)) {
            $segments = array_merge($segments, $this->apiEnding);
        }

        foreach ($segments as $key => $value) {
            $url = $url."$key=$value&";
        }

        //Remove the final &
        $url = substr($url, 0, -1);

        return $url;
    }
690564
protected function domainRoutingSetRequestedAndDefaultParams (array & $allMatchedParams) {
		/** @var $currentRoute \MvcCore\Route */
		$currentRoute = & $this->currentDomainRoute;
		$allMatchedParams[static::URL_PARAM_MODULE] = $currentRoute->GetModule();
		$this->defaultParams = array_merge(
			$currentRoute->GetDefaults(), $allMatchedParams
		);
		$this->requestedDomainParams = array_merge([], $allMatchedParams);
	}
240151
public function getAllLocalizedRoutes($segments = null, $leadSlash = true, $fullPath = false) {
        /*
         * routes with dynamic parameter(s)
         */
        if ($allRoutes = $this->getAllLocalazedDynamicRoutes($segments, $leadSlash, $fullPath)) {
            return $allRoutes;
        }
        
        /*
         * static routes
         */
        $allRoutes = [];
        // if segmets are not set - get from current request
        if (is_null($segments)) {
            $segments = \Request::segments();
        }
        elseif (is_string($segments)) {
            $segments = explode('/', $segments);
        }
        
        // if locale segment set - remove it from [0]
        if ($this->isSetLocaleSegmentInRoute($segments)) {
            array_shift($segments);
        }

        // loop each posiable locales and build localized rote
        foreach($this->getAllRoutelocales() as $locale) {
            $path = '';
            if (($this->getDefaultRoutelocale() !== $locale) || $this->isUsePrefixForDefaultLocale()) {
                // add locale to [0] segment
                $path = ($leadSlash ? '/' : '') . implode('/', array_merge([$locale], $segments));
            }
            else {
                // if it is default locale - DO NOT add it to [0] segment
                $path = ($leadSlash ? '/' : '') . implode('/', $segments);
            }
            $allRoutes[$locale] = $fullPath ? \URL::to($path) : $path;
        }
        return $allRoutes;
    }
1308670
public function execute(Routes $routes): void
	{
		$routeCollection = [];

		// Build table rows

		foreach($routes->getRoutes() as $route)
		{
			// Normalize action name

			$action = ($route->getAction() instanceof Closure) ? 'Closure' : $route->getAction();

			// Build table row

			$routeCollection[] =
			[
				$route->getRoute(),
				implode(', ', $route->getMethods()),
				$action,
				implode(', ', $route->getMiddleware()),
				implode(', ', $route->getConstraints()),
				(string) $route->getName(),
			];
		}

		// Draw table

		$headers =
		[
			'<green>Route</green>',
			'<green>Allowed methods</green>',
			'<green>Action</green>',
			'<green>Middleware *</green>',
			'<green>Constraints **</green>',
			'<green>Name</green>',
		];

		$this->table($headers, $routeCollection);

		$this->write('<green>*</green> <faded>Global middleware is not listed.</faded>');
		$this->write('<green>**</green> <faded>Global constraints are not listed.</faded>');
	}
492758
public function defaultRoute($controller, $action = null, array $args = [])
    {
        $this->_defaultRoute = [
            'route' => implode('/', [$this->module->id, $controller, (empty($action)) ? 'index' : $action]),
            'args' => $args,
            'originalArgs' => $args,
        ];
    }
576012
protected function _normalize($url, array $parts = []) {
        if (!is_string($url)) {
            $url = Router::url($url);
        }
        if (!$this->_matchHost($url)) {
            return null;
        }
        if (!$this->_matchRelative($url)) {
            return null;
        }
        $url = Router::parseRequest(new ServerRequest($this->_removeRelative($url)));
        $arr = [];
        foreach ($this->_parts as $part) {
            if (!isset($url[$part]) || (isset($parts[$part]) && !$parts[$part])) {
                continue;
            }
            if (is_array($url[$part])) {
                $url[$part] = implode('/', $url[$part]);
            }
            if ($part != 'pass') {
                $url[$part] = strtolower($url[$part]);
            }
            $arr[] = $url[$part];
        }
        return $this->_removeRelative(Router::normalize('/'.implode('/', $arr)));
    }
936425
protected function parseCustomSegments(array $segments)
    {
        if (\count($segments) >= 2) {
            $group = "{$segments[0]}/{$segments[1]}";

            if ($this->getLoader()->exists($group)) {
                return [null, $group, \implode('.', \array_slice($segments, 2))];
            }
        }

        return $this->parseBasicSegments($segments);
    }
1158591
private function processService(array &$segments): array
    {
        // init
        $processed = [];

        foreach ($segments as &$seg) {
            $jsonsegment = $this->processSegment($seg, $this->xmlSvc, null);
            $processed[$jsonsegment['key']] = $jsonsegment['value'];
        }

        return $processed;
    }
924896
public static function MakeNumberSegments($segments)
	{
		$NumberSegments = [];

		foreach ($segments as $segment)
		{
			$NumberSegments[] = new NumberSegment($segment);
		}

		return $NumberSegments;
	}
295112
private function getDynamicRouteIds(array $segments): array
    {
        $matched = [];
        $index = 0;

        do {
            $matched[] =
                $this->provider->getRoutesBySegmentValue($index, $segments[$index]) +
                $this->provider->getRoutesBySegmentValue($index, RouteDefinition::DYNAMIC_SEGMENT);
            $index++;
        } while (isset($segments[$index]));

        $matched[] = $this->provider->getRoutesBySegmentCount(\count($segments));

        return array_values(array_intersect_key(... $matched));
    }
802931
public function setRoutes() : void
    {
        if (is_null($this->routes)) {
            $this->routes = [];
            $routesConfig = $this->config->getParam('routes') ?? [];
            foreach ($routesConfig as $routeName => $routeArr) {
                $route = new Route(
                    $routeName,
                    $routeArr['methods'],
                    $routeArr['path'],
                    $routeArr['params_defaults'],
                    $routeArr['params_requirements'],
                    $routeArr['handler'],
                    $routeArr['handler_method'] ?? null
                );
                $this->routes[] = $route;
            }
        }
    }