dispatch the controller

@throws ControllerException
@return \Anonym\Route\Controller
762214
public function dispatch()
    {

        $name = $this->generateClassName($this->namespace, $this->class);

        // the controller instance
        $controller = App::make($name);


        if ($controller instanceof Controller) {
            // register the parameters
            $controller->runControllerWithParameters(ParameterBag::getParameters());


            // return the instance
            return $controller;
        } else {
            throw new ControllerException(sprintf('%s is not a instance of  controller', $name));
        }
    }
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);
        }
    }
1201662
public function handle()
    {
        try {
            $query = $this->di->request->getRoute();
            $parts = $this->di->request->getRouteParts();

            // Match predefined routes
            foreach ($this->routes as $route) {
                if ($route->match($query)) {
                    return $route->handle();
                }
            }

            // Default handling route as :controller/:action/:params using the dispatcher
            $dispatcher = $this->di->dispatcher;
            $dispatcher->setControllerName(isset($parts[0]) ? $parts[0] : 'index');

            if ($dispatcher->isValidController()) {
                $dispatcher->setActionName(isset($parts[1]) ? $parts[1] : 'index');

                $params = [];
                if (isset($parts[2])) {
                    $params = $parts;
                    array_shift($params);
                    array_shift($params);
                }
                $dispatcher->setParams($params);

                if ($dispatcher->isCallable()) {
                    return $dispatcher->dispatch();
                }
            }

            // Use the "catch-all" route
            if ($this->defaultRoute) {
                return $this->defaultRoute->handle();
            }

            // No route was matched
            $this->handleInternal('404');
        } catch (\Exception $e) {
            // Exception codes can match a route for a http status code
            $code = $e->getCode();
            $statusCodes = [403, 404, 500];
            if (in_array($code, $statusCodes)) {
                $this->di->flash->setMessage($e->getMessage());
                $this->handleInternal($code);
            } else {
                throw $e;
            }
        }
    }
989374
public function getController()
    {
        if(!($this->_controller instanceof ControllerInterface))
        {
            //Make sure we have a controller identifier
            if(!($this->_controller instanceof ObjectIdentifier)) {
                $this->setController($this->_controller);
            }

            $config = array(
                'request' 	 => $this->getRequest(),
                'user'       => $this->getUser(),
                'response'   => $this->getResponse(),
                'dispatched' => $this
            );

            $this->_controller = $this->getObject($this->_controller, $config);

            //Make sure the controller implements ControllerInterface
            if(!$this->_controller instanceof ControllerInterface)
            {
                throw new \UnexpectedValueException(
                    'Controller: '.get_class($this->_controller).' does not implement ControllerInterface'
                );
            }
        }

        return $this->_controller;
    }
1262862
def dispatch_action(req)
      controller = ROUTE_TO_CONTROLLER[req.path_info]
      fail Heartcheck::Errors::RoutingError if controller.nil?

      Logger.info "Start [#{controller}] from #{req.ip} at #{Time.now}"

      controller.new.index.tap do |_|
        Logger.info "End [#{controller}]\n"
      end
    end
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;
	}
197391
public function dispatch(ServerRequest $request, Response $response)
    {
        if (Router::getRequest(true) !== $request) {
            Router::pushRequest($request);
        }
        $beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));

        $request = $beforeEvent->getData('request');
        if ($beforeEvent->getResult() instanceof Response) {
            return $beforeEvent->getResult();
        }

        // Use the controller built by an beforeDispatch
        // event handler if there is one.
        if ($beforeEvent->getData('controller') instanceof Controller) {
            $controller = $beforeEvent->getData('controller');
        } else {
            $controller = $this->factory->create($request, $response);
        }

        $response = $this->_invoke($controller);
        if ($request->getParam('return')) {
            return $response;
        }

        $afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));

        return $afterEvent->getData('response');
    }
665530
public function DispatchRequest () {
		/** @var \MvcCore\IRoute */
		$route = & $this->router->GetCurrentRoute();
		if ($route === NULL) return $this->DispatchException('No route for request', 404);
		list ($ctrlPc, $actionPc) = [$route->GetController(), $route->GetAction()];
		$actionName = $actionPc . 'Action';
		$viewClass = $this->viewClass;
		$viewScriptFullPath = $viewClass::GetViewScriptFullPath(
			$viewClass::GetScriptsDir(),
			$this->request->GetControllerName() . '/' . $this->request->GetActionName()
		);
		if ($ctrlPc == 'Controller') {
			$controllerName = $this->controllerClass;
		} else if ($this->controller !== NULL) {
			$controllerName = '\\'.get_class($this->controller);
		} else {
			// `App_Controllers_<$ctrlPc>`
			$controllerName = $this->CompleteControllerName($ctrlPc);
			if (!class_exists($controllerName)) {
				// if controller doesn't exists - check if at least view exists
				if (file_exists($viewScriptFullPath)) {
					// if view exists - change controller name to core controller, if not let it go to exception
					$controllerName = $this->controllerClass;
				} else {
					return $this->DispatchException("Controller class `$controllerName` doesn't exist.", 404);
				}
			}
		}
		return $this->DispatchControllerAction(
			$controllerName,
			$actionName,
			$viewScriptFullPath,
			function (\Exception & $e) {
				return $this->DispatchException($e);
			}
		);
	}
1056695
public function dispatch($route, $request)
    {
        $request->setParam('Closure', $route[4]);

        if(isset($route[3]) && is_string($route[3])) {
            $view = $route[3];
            $data = $route[4];
            return ['view' => [$view, $data]];
        }
        elseif(isset($route[2]) && is_string($route[2])) {
            list($controller, $method) = explode('@', $route[2]);
            return ['controller' => [$controller, $method]];
        }
        elseif(isset($route[2]) && ($route[2] instanceof Closure || get_class($route[2]) === "Closure")) {
            $function = $route[2];
            $reflectionFunction = new ReflectionFunction($function);
            $numReqParam = $reflectionFunction->getNumberOfRequiredParameters();
            if($numReqParam > count($request->getParam('Closure'))) {
                throw new Exception('Invaliding number of required parameter passed in route\'s callable function: '.$route[1]);
            }
            ob_start();
            if($request->getParam('Closure') !== false && is_array($request->getParam('Closure')) ) {
                $return = call_user_func_array($route[2], $request->getParam('Closure'));
            }
            else {
                //$function();
                throw new Exception('Invaliding parameter passed in route\'s callable function: '.$route[1]);
            }
            $output = ob_get_clean();
            return ['output' => [$output, $return]];
        }
        else {
            throw new Exception('Invaliding route is registered for: '.$route[1]);
        }
    }
1281227
public function dispatch()
    {
        Eresus_Kernel::app()->getEventDispatcher()->dispatch('cms.admin.start');

        if (!UserRights(EDITOR))
        {
            $response = $this->authAction();
        }
        else
        {
            /** @var TAdminUI|TClientUI $page */
            $page = $this->getPage();
            $response = $page->render($this->getRequest());
        }
        return $response;
    }
197341
public function handle(HttpRequest $request)
    {
        $routeClass = Loader::load('route');

        $route = new $routeClass($this->route, $request->method());
        $controllerClassMethod = $route->resolve();
        if (false === $controllerClassMethod) {
            throw new Exception('Can\t resolve route.'); // TODO: Change to 404 response
        }

        $controllerClass = array_shift($controllerClassMethod);
        $controllerMethod = array_shift($controllerClassMethod);

        $controller = new $controllerClass($request);
        if (method_exists($controller, $controllerMethod)) {
            $output = call_user_func_array(array($controller, $controllerMethod), $route->get());
        } else {
            throw new ApplicationException(sprintf('Method "%s" doesn\'t exists in class "%s".', $method, $controllerClass)); // TODO: Change to 404 response
        }

        if ($request->isAjax()) {
            return json_encode($output);
        } else {
            return $output;
        }
    }
1022217
protected function dispatchToRouter()
    {
        return function ($request) {
            $this->app->instance('request', $request);

            return $this->router->dispatch($request);
        };
    }
70293
public function dispatch() {
		$handler = current($this->handlers);
		if (!$handler) {
			return;
		}

		$this->resolveHandler($handler);

		return $this;
	}
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));

    }
962081
public function dispatch(Request $request)
    {
        // Create the action instance
        $action = $this->resolveAction($request->getHandler());

        return $action->execute($request->getParameters());
    }
804907
protected function dispatchProcess(Request $request, Response $response)
    {
        if ($request->getController() === null || $request->getAction() === null) {
            throw new ArchException('Controller or action not defined. Router problem?');
        }
        $actionMethod = $request->getAction() . 'Action';
        ob_start();
        $this->dispatched = true;
        $controllerName = $request->getController();
        if (!$controllerName) {
            throw new ArchException('Controller is undefined');
        }
        $controller = Container::getController($controllerName);
        if (!($controller instanceof \Osf\Controller\Action)) {
            throw new ArchException('Your controller class for application ' . $request->getController() . ' must extends \Osf\Controller\Action');
        }
        if (!method_exists($controller, $actionMethod)) {
            throw new HttpException('Action ' . $actionMethod . '() not found in controller class of application ' . $request->getController(), 404);
        }
        if ($this->dispatched) {
            $controller->preDispatch();
            self::debug('Call ' . $controllerName . '::' . $actionMethod . '()');
            $viewParams = $controller->$actionMethod();
            $controller->postDispatch();
            $content = ob_get_clean();
            $content && $response->appendBody($content);
            if ($viewParams === null) {
                $viewParams = [];
            } elseif (!is_array($viewParams)) {
                throw new ArchException('Action must return an array or null');
            }
        } else {
            self::debug('No call of ' . $controllerName . '::' . $actionMethod . '(), not dispatched');
            ob_clean();
        }
        if ($this->dispatched && $this->renderView) {
            $response->appendBody(Container::getView()->register($viewParams)->render());
        }

        return $this;
    }
885641
protected function _resolveRequest(DispatcherContext $context)
    {
        //Resolve the controller
        if($context->request->query->has('view')) {
            $this->setController($context->request->query->get('view', 'cmd'));
        }

        //Resolve the controller action
        if($context->request->data->has('_action')) {
            $this->setControllerAction($context->request->data->get('_action', 'cmd'));
        }
    }