Prepare pipeline requests and send through router.

@param $request
@return mixed
559072
protected function sendRequestThroughRouter($request)
    {
        $this->app->bootApplication($request);
        $this->pipeline = new Pipeline($this->container);

        return $this->pipeline
            ->send($request)
            ->through($this->parseMiddlewareToPipelines($this->getMiddleware()), 'handle')
            ->then($this->dispatchToRouter())
            ->run();
    }
767154
public function handle($request)
	{
		try
		{
			$response = $this->sendRequestThroughRouter($request);
		}
		catch (Exception $e)
		{
			$this->reportException($e);

			$response = $this->renderException($request, $e);
		}

		$this->app['events']->fire('kernel.handled', [$request, $response]);

		return $response;
	}
1231363
public function execute($request)
	{
		$router = $request->getRouter();
		$builder = new \Ergo\Http\ResponseBuilder();

		// these parameters are interpolated into the redirected url
		$params = $request->getRouteMatch()->getParameters();

		// TODO: return a full RFC compliant url
		return $builder
			->found($router->buildUrl($this->_route, $params))
			->build()
			;
	}
606735
protected function runRouteWithinStack(Route $route, Request $request)
    {
        $middleware = $this->gatherRouteMiddlewares($route);
        
        return (new Pipeline($this->container))
                        ->send($request)
                        ->through($middleware)
                        ->then(function ($request) use ($route) {
                            return $this->prepareResponse(
                                $request,
                                $route->run($request)
                            );
                        });
    }
1109997
private static function _run($request)
    {
        // Whether or not we have matched the URL to a route
        $matched_route = false;

        $request = '/' . $request;

        //make sure the request has a trailing slash
        $request = rtrim($request, '/') . '/';

        $request = str_replace("//","/",$request);

        // Sort the array by priority
        ksort(self::$_routes);


        // Loop through each priority level
        foreach (self::$_routes as $priority => $routes) {
            // Loop through each route for this priority level
            foreach ($routes as $source => $destination) {

                // Does the routing rule match the current URL?
                if (preg_match($source, $request, $matches)) {
                    // A routing rule was matched
                    $matched_route = TRUE;
                    $attr = implode('/',array_intersect_key($matches, array_flip(array_filter(array_keys($matches), 'is_string'))));
                    self::$_attr = explode('/', trim($attr, '/'));
                    self::_set_callback($destination);
                }



            }
        }

        if(!$matched_route)
        {
            if($request != '/')
            {
                self::_set_callback($request);
            }
        }

    }
403480
protected function call($request)
    {
        if(!isset($request['query']))
        {
            $request['query'] = [];
        }

        $method  = 'GET';
        $headers = $this->getHeaders();
        $query   = http_build_query($request['query']);
        $url     = "{$this->domain}/{$request['route']}?$query";

        try {
            $request = $this->getClient()->request($method, $url, [
                'headers' => $headers
            ]);

            $response = $request->getBody()->getContents();

            return json_decode($response, true);

        } catch (RequestException $e) {
            $response = $e->getResponse();
            $response = json_decode($response, true);
            return $response;
        } catch (\Exception $e) {
            return ['error' => $e->getCode(), 'error_description' => $e->getMessage()];
        }
    }
604234
public function handleHttpRequest($request)
    {
        $this->parseRequestBase($request);

        $data = $this->parseRule();
        $path = $data[0] ?? $this->routeParams->path;
        if ($path) {
            $this->parsePath($path);
        }
        if (!empty($data[1])) {
            foreach ($data[1] as $name => $value) {
                $request->get[$name] = $value;
            }
        }
    }
673846
protected function sendRequestThroughRouter(Request $request)
    {
        return (new Pipeline($this->app))->send($request)->then(function ($request) {

            /**
             * @var Response $response
             */
            $response = $this->router->dispatch($request);

            if (property_exists($response, 'exception') && $response->exception instanceof Exception) {
                throw $response->exception;
            }

            return $response;
        });
    }
43985
protected function redirectTo($request)
    {
        session()->put('loginRedir', $_SERVER["REQUEST_URI"]);
        session()->put('loginRedirTime', time());
        if (!$request->expectsJson()) {
            return route('login');
        }
    }
587968
protected function handle(Request $request)
    {
        try {
            list($routeInformation, $parameters) = $this->findRoute($request);

            return (new Pipeline($this->container))
                ->through($routeInformation['middlewares'])
                ->send($request)
                ->then(function (Request $request) use ($routeInformation, $parameters) {
                    if ($routeInformation['action'] instanceof Closure) {
                        return call_user_func_array($routeInformation['action'], $parameters);
                    }

                    list($controller, $action) = $routeInformation['action'];
                    $controllerInstance = new $controller;

                    if ($controllerInstance instanceof KeeperBaseController) {
                        $controllerInstance->setContainer($this->container);
                        $controllerInstance->setRequest($request);
                    }

                    return call_user_func_array([$controllerInstance, $action], $parameters);
                });

        } catch (Throwable $exception) {
            if ($this->exceptionHandler) {
                return $this->exceptionHandler->handle($exception, $request);
            }

            return new Response((string)$exception, 500);
        }
    }
1086650
protected function sendRequestThroughRouter($request)
	{
		$this->app->instance('request', $request);

		Facade::clearResolvedInstance('request');

		$this->bootstrap();

		return (new Pipeline($this->app))
		            ->send($request)
		            ->through($this->middleware)
		            ->then($this->dispatchToRouter());
	}
414083
protected function gatherRouteMiddleware($request)
    {
        if (! is_null($route = $request->route())) {
            return $this->router->gatherRouteMiddleware($route);
        }

        return array();
    }
799728
private function match($request)
    {
        $route = $this->router->match(
            $request->getUri()->getPath(),
            $request->getMethod()
        );
        if (!$route) {
            // not matched. dispatch the next middleware.
            return $this->next ? $this->next->__invoke($request) : null;
        }
        return $this->dispatch($request, $route);
    }
1284036
public function handleHttpRequest($request)
    {
        $this->parseRequestBase($request);

        if (isset($request->header['x-rpc']) && $request->header['x-rpc'] == 1) {
            $this->routeParams->isRpc          = true;
            $this->routeParams->params         = $request->post ?? $request->get ?? [];
            $this->routeParams->controllerName = 'Rpc';
            $this->routeParams->methodName     = 'Index';
            $this->controllerClassName         = '\PG\MSF\Controllers\Rpc';
            $this->routeParams->path           = '/Rpc/Index';
        } else {
            if ($this->routeParams->path) {
                $this->parsePath($this->routeParams->path);
            }
        }
    }
823398
protected function processRaw(Request $request) {
		$resolver = $this->getResolver();
		$resolver->sortRoutes();

		$route = $resolver->getRoute($request);

		if($route) {
			$request->setRoute($route);
			$controllerClass = $route->getController();
			$action = $route->getAction();

			$controller = new $controllerClass();
			$controller->setFlash($this->flash);
			$controller->setResolver($this->resolver);
			$controller->setContainer($this->container);

			$this->prepareController($controller, $action, $request, $route);
		}
		else
			$controller = null;

		if($response = $this->hookManager->trigger('Asgard.Http.Start', [$request, $controller]))
			return $response;

		if($response = $this->executeStart($request, $controller))
			return $response;

		if($route === null)
			throw new Exception\NotFoundException;

		return $controller->run($action, $request);
	}
846472
public function handle($request)
    {
        $this->loadAuthManager();
        
        try {
            $response = $this->sendRequestThroughRouter($request);
            $response = $response->getContent();
            
            $json = json_decode($response, true);
            if (json_last_error() == JSON_ERROR_NONE) {
                $response = $json;
            }
        } catch (Exception $e) {
            if ($e instanceof NotFoundHttpException) {
                $response = $e;
            } else {
                throw $e;
            }
        }
        
        $this->app['events']->fire('wskernel.handled', [$request, $response]);
        
        return $response;
    }
909005
public function execute($request)
	{
		$match = $this->lookup($request->getUrl()->getPath());
		$controller = $this->controller($match->getName());
		return $controller->execute(new RoutedRequest($request, $match, $this));
	}