Dispatch a request to a given controller and method.

@param  \Illuminate\Routing\Route  $route
@param  mixed  $controller
@param  string  $method
@return mixed
166862
public function dispatch(Route $route, $controller, $method)
    {

        // This is not very nice but with the current structure we have to throw
        // the previously created controller away.
        // For further implementations more cleanup has to be done
        $instance = $this->makeController(is_object($controller) ? get_class($controller) : $controller);

        $parameters = $this->resolveClassMethodDependencies(
            $route->parametersWithoutNulls(), $instance, $method
        );

        if ($this->creator && method_exists($this->creator, 'modifyMethodParameters')) {
            $this->creator->modifyMethodParameters($instance, $method, $parameters);
        }

        if (method_exists($instance, 'callAction')) {
            return $instance->callAction($method, $parameters);
        }

        return $instance->{$method}(...array_values($parameters));

    }
559258
public function execute(Request $request, Route $route, $parameters)
    {
        $request->attributes->set('_controller', $this->getControllerCallback());
        $app = Facade::getFacadeApplication();
        $controllerResolver = $app->make(ApplicationAwareControllerResolver::class);
        $callback = $controllerResolver->getController($request);
        $argumentsResolver = $app->make(ArgumentResolver::class);

        $arguments = $argumentsResolver->getArguments($request, $callback);
        $controller = $callback[0];
        $method = $callback[1];

        if (method_exists($controller, 'on_start')) {
            $controller->on_start();
        }

        if (method_exists($controller, 'runAction')) {
            $response = $controller->runAction($method, $arguments);
        } else {
            $response = call_user_func_array([$controller, $method], $arguments);
        }

        if ($response instanceof Response) {
            // note, our RedirectResponse doesn't extend Response, it extends symfony2 response
            return $response;
        }

        if ($response instanceof AbstractView) {
            $content = $response->render();
        } else if (method_exists($controller, 'getViewObject')) {
            $content = null;
            $view = $controller->getViewObject();
            if (is_object($view)) {
                $view->setController($controller);
                if (isset($view) && $view instanceof AbstractView) {
                    $content = $view->render();
                }
            }
        } else {
            $content = $response;
        }

        if (is_object($content)) {
            return $content;
        }

        $response = new Response();
        $response->setContent($content);
        return $response;
    }
134750
public function dispatch(Route $route, Request $request, $controller, $method)
	{
		// First we will make an instance of this controller via the IoC container instance
		// so that we can call the methods on it. We will also apply any "after" filters
		// to the route so that they will be run by the routers after this processing.
		$instance = $this->makeController($controller);

		$this->assignAfter($instance, $route, $request, $method);

		$response = $this->before($instance, $route, $request, $method);

		// If no before filters returned a response we'll call the method on the controller
		// to get the response to be returned to the router. We will then return it back
		// out for processing by this router and the after filters can be called then.
		if (is_null($response))
		{
			$response = $this->call($instance, $route, $method);
		}

		return $response;
	}
1244354
protected function dispatchMethod($request, $route)
    {
        list($path, $var) = $this->parseUrlPath($route);

        $route = str_replace('/', '@', implode('/', $path));
        $method = strpos($route, '@') ? explode('@', $route) : $route;

        return new CallbackDispatch($request, $this, $method, $var);
    }
264
public function dispatch(Route $route, Request $request = null)
    {
        $context = $this->context;

        if (empty($this->context) && !empty($request)) {
            // If we have no context, but do have a request, prepare a context to store path variables in.
            // Otherwise routing path variables would be lost for no good reason.
            $context = new Context();
            $context->registerInstance($request);
        }

        if (!empty($context)) {
            // If we have a context, ensure that the route is made available in it.
            $context->registerInstance($route);

            if (!empty($request)) {
                // If we have a request, map the path variables and pass them to the context as primitive types by name.
                // This will allow us to inject info from a route e.g. "/view/$userId" to a $userId variable.
                $pathVariables = VariableUrl::extractUrlVariables($request->getRequestUri(), $route->getPattern());

                foreach ($pathVariables as $name => $value) {
                    $context->registerVariable($name, $value);
                }
            }
        }

        return $route->action($context);
    }
311297
public function dispatchRoute(Parsed $route, array $parameters = [])
    {
        $handler = $route->getHandler();
        if (isset($handler['controler']) && isset($handler['action'])) {
            $routePlaceholders             = $route->getPlaceholders();
            list($controllerName, $action) = $this->resolveControlerAction(
                $route->getParameters(),
                $routePlaceholders,
                $handler
            );

            // Create instance of target class
            $controller = new $controllerName();
            // Create class method name with prefix
            $methodName = $this->actionName.$action;

            $parameterMap = $this->getMethodParameters(
                $controllerName,
                $methodName
            );

            $methodParameters = $this->getFunctionArgumentsControlers(
                $parameterMap,
                $route->getParameters(),
                $routePlaceholders,
                $handler
            );

            return call_user_func_array(
                [
                    $controller,
                    $methodName
                ],
                $methodParameters
            );
        }

        return $this->dispatchNotFound();
    }
832688
private function dispatch($request, $route)
    {
        if ($route->matched()) {
            $request = $request->withPathToMatch($route->matched(), $route->trailing());
        }
        // dispatch the route!
        return $this->dispatcher->withRoute($route)->__invoke($request);
    }
982827
public function dispatch(Request $request)
    {
        $pathInfo = $request->getPathInfo();
        $method   = $request->getMethod();

        $route = $this->collection->find($method, $pathInfo);

        if ( ! $route) {
            throw new \Exception('Route not found !');
        }

        return $this->dispatcher->dispatch($route);
    }
1141974
private function callControllerMethod(Controller $controller, $method)
    {
        return App::call([$controller, $method], ParameterBag::getParameters());
    }
1001429
public function dispatch($method, $uri)
	{
	    $this->loadDefaultRoutes();
	    
	    $routeArguments = [];
	    
		// strip base url
		if (strpos($_SERVER['SCRIPT_NAME'], $uri) === 0) {
		    $uri = '/';
		} else {
		    $uri = str_replace($_SERVER['SCRIPT_NAME'], '', $uri);
            $uri = '/' . trim($uri, '/');
            
            // separate uri to uri and params
            $params = [];
            if (strpos($uri, '/p/')) {
                $parts = explode('/p/', $uri, 2);
                $uri = $parts[0];
                $params = $parts[1];
            } elseif (strpos($uri, '&')) {
                $parts = explode('&', $uri, 2);
                $uri = $parts[0];
                $params = $parts[1];
            }
            
            if ($params) {
                $routeArguments = UriHelper::parseQueryFromPath($params);
            }
		}
		
		/**
		 * @var array $routeInfo
		 * [0]  not found
		 * [1, $routeIndentifier, [GET, $request_uri]] found 
		 * [2, ['GET', 'OTHER_ALLOWED_METHODS']] not allowed
		 * 
		 * @link   https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php
		 */
		$routeInfo = $this->createDispatcher()->dispatch($method, $uri);
		
		$result = new DispatchResult();
		$result->flag = $routeInfo[0];
		
		if ($routeInfo[0] === Dispatcher::FOUND) {
			$route = $this->lookupRoute($routeInfo[1]);
			
			foreach ($routeInfo[2] as $k => $v) {
				$routeArguments[$k] = urldecode($v);
			}
			$route->setArguments($routeArguments);
			
			$result->route = $route;
		} elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
			$result->info = $routeInfo[RouterInterface::ALLOWED_METHODS];
		}
		//print_r($this->getRoutesPatterns()); print_r($result); exit;
		
		return $result;
	}
95120
protected function bindToController($request, $url, $controller)
    {
        $array  = explode('|', $url, 2);
        $action = !empty($array[0]) ? $array[0] : $this->router->config('default_action');
        $param  = [];

        if (!empty($array[1])) {
            $this->parseUrlParams($request, $array[1], $param);
        }

        return new ControllerDispatch($request, $this, $controller . '/' . $action, $param);
    }
1260926
public function dispatch(int $status, string $path, string $method, $route)
    {
        // not found
        if ($status === RouterInterface::NOT_FOUND) {
            return $this->handleNotFound($path, $method);
        }

        // method not allowed
        if ($status === RouterInterface::METHOD_NOT_ALLOWED) {
            return $this->handleNotAllowed($path, $method, $route);
        }

        // trigger route found event
        $this->fire(self::ON_FOUND, [$path, $route]);

        $result = null;
        $options = $route->getOptions();

        // fire enter event
        // schema,domains ... metadata validate
        if (isset($options['enter']) && false === RouteHelper::call($options['enter'], [$options, $path])) {
            return $result;
        }

        $handler = $route->getHandler();
        $args = $route->getParams();

        try {
            // trigger route exec_start event
            $this->fire(self::ON_EXEC_START, [$path, $route]);

            $globChains = $this->getRouter()->getChains();
            $chains = $route->getChains();

            $result = $this->callHandler($path, $method, $handler, $args);

            // fire leave event
            if (isset($options['leave'])) {
                RouteHelper::call($options['leave'], [$options, $path]);
            }

            // trigger route exec_end event
            $this->fire(self::ON_EXEC_END, [$path, $route, $result]);
        } catch (\Throwable $e) {
            // trigger route exec_error event
            if ($cb = $this->getOption(self::ON_EXEC_ERROR)) {
                return RouteHelper::call($cb, [$e, $path, $route]);
            }

            throw $e;
        }

        return $result;
    }
229197
public function dispatch(string $path, string $method = 'get')
    {
        $route = $this->_match($path, $method);

        $obj = [];

        if ($route) {
            $dispatch = $route->getStorage();
            $call = $dispatch['dispatch'] ?? [];
            $before = $dispatch['before'] ?? [];
            $after = $dispatch['after'] ?? [];
            $type = $dispatch['type'] ?? Producer::PRODUCER_SYNC;
            $params = $route->getParams();
            if (is_array($call) and class_exists($call[0])) {
                $params = $params === null ? [] : $params;
                return $this->_runProducer($call, $params, $before, $after, $type);
            }
            if (is_string($call)) {
                $obj = [$call];
            }
            return $obj;
        } else {
            return ['code' => 404];
        }

    }
174505
protected function runRoute(Request $request, Route $route)
    {
        $request->setRouteResolver(function () use ($route) {
            return $route;
        });

        $this->events->dispatch(new Events\RouteMatched($route, $request));

        return $this->prepareResponse($request,
            $this->runRouteWithinStack($route, $request)
        );
    }
164363
public function map($uri, $method)
    {
        if ($uri === '/') {
            $uri = '';
        }

        $controller = $this;

        return $this->app->map(
            $this->baseUri.$uri,
            function () use ($controller, $method) {
                $params = func_get_args();
                $i = 0;
                $a = preg_replace_callback('/:(\w+)/', function($matches) use ($controller, $params, &$i) {
                    $value = @$params[$i++];
                    $controller->routeData($matches[1], $value);
                    return $value;
                }, $controller->baseUri);
                $controller->delegate($method, array_slice($params, $i));
            }
        );
    }
779661
public function addRoute(string $path, string $controller, string $action = 'index', string $method = Request::METHOD_GET) : self
    {
        $endPoint = new RouteEndpoint($this->namespace, $controller, $action, $method);
        $this->routes[] = new Route($path, $endPoint);
        
        return $this;
    }
1063262
public function dispatch( Route $route, Request $request, $controller, $method )
	{
		$instance = $this->makeController( $controller );

		return $this->callWithinStack( $instance, $route, $request, $method );
	}