Prepares the route dispatcher.

@return void
432794
protected function bootstrapDispatcher(): void
    {
        $this->routeDispatcher = FastRoute\simpleDispatcher(function (RouteCollector $collector) {
            foreach ($this->routes as $routeName => $route) {
                $collector->addRoute($route['method'], $route['pattern'], $route['handler']);
            }
        });
    }
316669
protected function prepare()
    {
        return [
            'route'             => str_replace(app('url')->to('/'), '', Request::url()),
            'ip_address'        => GeoIPFacade::getClientIP(),
            'user_agent'        => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No UserAgent',
            'created_at'        => new DateTime(),
            'updated_at'        => new DateTime(),
            'type'              => 'dispatched',
            'user_id'           => auth()->guest() ? null : auth()->user()->id,
            'brand_id'          => brand_id(),
            'additional_params' => $this->additionalParams,
            'related_data'      => $this->relatedData
        ];
    }
1210473
protected function prepareRequest(): void
    {
        // HTTP method
        $method = Request::getMethod();
        $this->method = strtoupper($method);

        // get path
        // %module% / %controller% / %id% / %relation% / %id%
        $path = Router::getCleanUri();

        $this->params = explode('/', rtrim($path, '/'));

        // module
        $this->module = array_shift($this->params);

        // controller
        $this->controller = array_shift($this->params);

        $data = Request::getParams();

        unset($data['_method'], $data['_module'], $data['_controller']);

        $this->data = array_merge($data, $this->data);

        $primary = $this->crud->getPrimaryKey();

        $this->primary = array_intersect_key($this->data, array_flip($primary));
    }
983109
private function prepare()
    {
        try {
            $projectRoot = dirname(__DIR__, 4);
            if (!$this->router) {
                $this->useRoute($projectRoot . DIRECTORY_SEPARATOR . "route.json");
            }
            if (!$this->logDirectory) {
                $this->useLogger($projectRoot . DIRECTORY_SEPARATOR . "log");
            }
            $this->getErrorHandler()->register();
            unset($this->logDirectory);
        } catch (InvalidArgumentException $e) {
            throw new RuntimeException(
                "Can't prepare application: " . $e->getMessage());
        }
    }
678101
private function prepareRouterData()
    {
        $routers = [];
        $reverse = [];
        $path = Application::getInstance()->getPath() . '/modules/*/controllers/*.php';
        foreach (new \GlobIterator($path) as $file) {
            /* @var \SplFileInfo $file */
            $module = $file->getPathInfo()->getPathInfo()->getBasename();
            $controller = $file->getBasename('.php');
            $controllerInstance = new Controller($module, $controller);
            $meta = $controllerInstance->getMeta();
            if ($routes = $meta->getRoute()) {
                foreach ($routes as $route => $pattern) {
                    if (!isset($reverse[$module])) {
                        $reverse[$module] = [];
                    }

                    $reverse[$module][$controller] = ['route' => $route, 'params' => $meta->getParams()];

                    $rule = [
                        $route => [
                            'pattern' => $pattern,
                            'module' => $module,
                            'controller' => $controller,
                            'params' => $meta->getParams()
                        ]
                    ];

                    // static routers should be first, than routes with variables `$...`
                    // all routes begin with slash `/`
                    if (strpos($route, '$')) {
                        $routers[] = $rule;
                    } else {
                        array_unshift($routers, $rule);
                    }
                }
            }
        }
        $routers = array_merge(...$routers);
        return [$routers, $reverse];
    }
293350
protected function buildDispatcher()
    {
        $this->app->singleton(
            'Ratchet\Wamp\WampServerInterface',
            Dispatcher::class
        );
        
        return $this->Dispatcher = $this->app->make('Ratchet\Wamp\WampServerInterface', [$this->getSession(), $this->buildKernel(), clone $this->out]);
    }
109928
private static void prepareRoutes() {
        injector.getInstance(MangooBootstrap.class).initializeRoutes();
        
        Router.getRequestRoutes().forEach((RequestRoute requestRoute) -> {
            if (!methodExists(requestRoute.getControllerMethod(), requestRoute.getControllerClass())) {
                LOG.error("Could not find controller method '{}' in controller class '{}'", requestRoute.getControllerMethod(), requestRoute.getControllerClass());
                failsafe();
            }
            
            if (requestRoute.hasAuthorization() && (!MangooUtils.resourceExists(Default.MODEL_CONF.toString()) || !MangooUtils.resourceExists(Default.POLICY_CSV.toString()))) {
                LOG.error("Route on method '{}' in controller class '{}' requires authorization, but either model.conf or policy.csv is missing", requestRoute.getControllerMethod(), requestRoute.getControllerClass());
                failsafe();
            } 
        });
    }
882179
private function prepareRouterContext()
    {
        if ($this->generatedRouteHost) {
            $this
                ->router
                ->setContext($this->modifiedContext);

            /**
             * When a Host is set for the image route,
             * we need to change the route context URL.
             */
            $this
                ->router
                ->getContext()
                ->setHost($this->generatedRouteHost);
        }
    }
902832
private function buildRoutes(): void
    {
        if ($this->loaded['routes']) {
            return;
        }

        $this->loaded['routes'] = true;

        $this->routes = new RouteCollection(
            $this->getBaseCodeRoute(),
            $this->getBaseRouteName(),
            $this->getBaseRoutePattern(),
            $this->getBaseControllerName()
        );

        $this->routeBuilder->build($this, $this->routes);

        $this->configureRoutes($this->routes);

        foreach ($this->getExtensions() as $extension) {
            $extension->configureRoutes($this, $this->routes);
        }
    }
1022884
protected function prepare()
    {
        //Force passice mode if not specified
        $this->addOption('passive', true);

        //To make call on different files, we must retrieve the root and apply commands to the path
        $tmp = clone $this->getUrl();
        $tmp->path('');
        $this->addOption('url', $tmp->toString());
    }
1048981
public function prepare()
    {
        $this->preparedRoutes = true;
        foreach($this->routers as $router) {
            $this->prepareRoutes($router->routes);
        }
    }
514606
public function prepareRouter()
    {
        $router = new Router();

        // Inject Logger if we have one
        if ($this->logger) {
            $router->setLogger($this->logger);
        }

        // Build the matcher stack
        $router->addMatcher($this->buildDefaultMatcher());

        if ($this->hasRoutingTemplates()) {
            $router->addMatcher($this->buildTemplateMatcher());
        }

        if ($this->hasRoutingConfig()) {
            $router->addMatcher($this->buildSymfonyMatcher());
        }

        return($router);
    }
389641
public static function dispatch()
    {
        $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $method = $_SERVER['REQUEST_METHOD'];

        $searches = array_keys(static::$patterns);
        $replaces = array_values(static::$patterns);

        $found_route = false;

        self::$routes = preg_replace('/\/+/', '/', self::$routes);

        // Check if route is defined without regex
        if (in_array($uri, self::$routes)) {
            $route_pos = array_keys(self::$routes, $uri);
            foreach ($route_pos as $route) {

                // Using an ANY option to match both GET and POST requests
                if (self::$methods[$route] == $method || self::$methods[$route] == 'ANY' || in_array($method, self::$maps[$route])) {
                    $found_route = true;

                    // If route is not an object
                    if (!is_object(self::$callbacks[$route])) {

                        // Grab all parts based on a / separator
                        $parts = explode('/', self::$callbacks[$route]);

                        // Collect the last index of the array
                        $last = end($parts);

                        // Grab the controller name and method call
                        $segments = explode('@', $last);

                        // Instanitate controller
                        $controller = new $segments[0]();

                        // Call method
                        $controller->{$segments[1]}();

                        if (self::$halts) return;
                    } else {
                        // Call closure
                        call_user_func(self::$callbacks[$route]);

                        if (self::$halts) return;
                    }
                }
            }
        } else {
            // Check if defined with regex
            $pos = 0;
            foreach (self::$routes as $route) {
                if (strpos($route, ':') !== false) {
                    $route = str_replace($searches, $replaces, $route);
                }

                if (preg_match('#^' . $route . '$#', $uri, $matched)) {
                    if (self::$methods[$pos] == $method || self::$methods[$pos] == 'ANY' || in_array($method, self::$maps[$pos])) {
                        $found_route = true;

                        // Remove $matched[0] as [1] is the first parameter.
                        array_shift($matched);

                        if (!is_object(self::$callbacks[$pos])) {

                            // Grab all parts based on a / separator
                            $parts = explode('/', self::$callbacks[$pos]);

                            // Collect the last index of the array
                            $last = end($parts);

                            // Grab the controller name and method call
                            $segments = explode('@', $last);

                            // Instanitate controller
                            $controller = new $segments[0]();

                            // Fix multi parameters
                            if (!method_exists($controller, $segments[1])) {
                                echo "controller and action not found";
                            } else {
                                call_user_func_array(array($controller, $segments[1]), $matched);
                            }

                            if (self::$halts) return;
                        } else {
                            call_user_func_array(self::$callbacks[$pos], $matched);

                            if (self::$halts) return;
                        }
                    }
                }
                $pos++;
            }
        }

        // Run the error callback if the route was not found
        if ($found_route == false) {
            if (!self::$error_callback) {
                self::$error_callback = function () {
                    header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found");
                    throw new \Exception(Config::get('error_message'));
                };
            } else {
                if (is_string(self::$error_callback)) {
                    self::get($_SERVER['REQUEST_URI'], self::$error_callback);
                    self::$error_callback = null;
                    self::dispatch();
                    return;
                }
            }
            call_user_func(self::$error_callback);
        }
    }
1091383
public function dispatch($http_method, $url)
    {
        if ($this->dispatcher === null) {
            throw new \RuntimeException('Route dispatcher is not initialized');
        }

        $this->dispatched_http_method = $http_method;
        $this->dispatched_url = $url;
        $this->route_info = $this->dispatcher->dispatch($http_method, $url);

        return $this->route_info;
    }
1077175
protected function setUp()
	{
		$this->register(array(
			'finding' => Finding::class,
			'route' => Route::class,
			'group' => Group::class
			));

        $this->addDefaultGroupHandler(new ClosureHandler());
        $this->addDefaultGroupHandler(new ArrayHandler());
//        $this->addDefaultGroupHandler(new PathHandler());

		return $this;
	}
993600
protected function initRoutes()
    {
        $fileLocator = new FileLocator([__DIR__, SettingsPath::FULL_ROOT]);
        $loader = new YamlFileLoader($fileLocator);
        $routes = $loader->load('coreroutes.yaml');

        $headers = [
            'X-SESSION-ID',
            'X-UTC-OFFSET',
            'X-Requested-With',
            'X-File-Name',
        ];

        $this->request = Request::createFromGlobals();
        $this->response = new JsonResponse();

        $this->response->headers->set('Access-Control-Allow-Origin', '*');
        $this->response->headers->set('Access-Control-Allow-Headers', implode(',', $headers));

        $context = new RequestContext();
        $context->fromRequest($this->request);

        $this->url_matcher = new UrlMatcher($routes, $context);
    }
829442
public static function dispatch()
    {

        $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $method = $_SERVER['REQUEST_METHOD'];

        $searches = array_keys(static::$patterns);
        $replaces = array_values(static::$patterns);

        self::$routes = str_replace('//', '/', self::$routes);

        $foundRoute = false;

        // Parse query parameters
        {
            $query = '';
            $q_arr = array();
            if (strpos($uri, '&') > 0) {
                $query = substr($uri, strpos($uri, '&') + 1);
                $uri = substr($uri, 0, strpos($uri, '&'));
                $q_arr = explode('&', $query);
                foreach ($q_arr as $q) {
                    $qobj = explode('=', $q);
                    $q_arr[] = array($qobj[0] => $qobj[1]);
                    if (!isset($_GET[$qobj[0]])) {
                        $_GET[$qobj[0]] = $qobj[1];
                    }
                }
            }
        }

        // Check if route is defined without regex

        if (in_array($uri, self::$routes)) {

            $routePos = array_keys(self::$routes, $uri);

            // Foreach route position
            foreach ($routePos as $route) {

                if (self::$methods[$route] == $method || self::$methods[$route] == 'ANY') {
                    $foundRoute = true;

                    // If route is not an object

                    if (!is_object(self::$callbacks[$route])) {

                        // Call object controller and method

                        self::invokeObject(self::$callbacks[$route]);
                        if (self::$halts) return;

                    } else {

                        // Call closure

                        call_user_func(self::$callbacks[$route]);
                        if (self::$halts) return;

                    }
                }

            }

        } else {

            // Check if defined with regex
            $pos = 0;

            // Foreach routes

            foreach (self::$routes as $route) {

                $route = str_replace('//', '/', $route);

                if (strpos($route, ':') !== false) {
                    $route = str_replace($searches, $replaces, $route);
                }

                if (preg_match('#^' . $route . '$#', $uri, $matched)) {

                    if (self::$methods[$pos] == $method || self::$methods[$pos] == 'ANY') {
                        $foundRoute = true;

                        // Remove $matched[0] as [1] is the first parameter.

                        array_shift($matched);

                        if (!is_object(self::$callbacks[$pos])) {

                            // Call object controller and method

                            self::invokeObject(self::$callbacks[$pos], $matched);
                            if (self::$halts) return;

                        } else {

                            // Call closure
                            call_user_func_array(self::$callbacks[$pos], $matched);
                            if (self::$halts) return;

                        }
                    }
                }

                $pos++;
            }
        }

        // Run the error callback if the route was not found

        if (!$foundRoute) {

            if (!self::$errorCallback) {

                self::$errorCallback = function () {
                    header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found");
                    echo '404';
                };
            }

            if (!is_object(self::$errorCallback)) {

                // Call object controller and method
                self::invokeObject(self::$errorCallback, null, 'No routes found.');
                if (self::$halts) return;

            } else {

                call_user_func(self::$errorCallback);
                if (self::$halts) return;

            }
        }
    }