Handle new controller@method from route.

@param  string  $controller
@param  string  $method

@return mix
343823
public function handleController($controller, $method)
    {
        if($this->app->findController($controller)) {
            $controllerClass = "App\\Controller\\".$controller;
            $this->controller = new $controllerClass();
        }
        if($this->app->hasMethod($this->controller, $method)) {
            self::$instance = $this;
            ob_start();
            $return = $this->controller->$method();
            $output = ob_get_clean();
            self::$instance = null;
        }
        if($return !== null) {
            //handle returned value
        }
        $output = $output ?: null;
        return $output;
    }
993735
public Route to(Controller controller, String method) {
        Preconditions.checkNotNull(controller);
        Preconditions.checkNotNull(method);
        this.controller = controller;
        try {
            this.controllerMethod = verifyThatControllerAndMethodExists(controller.getClass(),
                    method);
        } catch (Exception e) {
            throw new IllegalArgumentException(ERROR_CTRL + method + ERROR_IN + controller
                    .getClass() + "`, or the method is invalid", e);
        }
        return _build();
    }
341598
public function dispatch(Route $route, $controller, $method)
    {
        $parameters = $this->resolveClassMethodDependencies(
            $route->parametersWithoutNulls(), $controller, $method
        );

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

        return call_user_func_array(array($controller, $method), $parameters);
    }
207765
public function map($method, $route, $handler)
    {
        $this['router']->map($method, $route, $handler);

        return $this;
    }
126933
protected function callController($controller)
    {
        if (is_string($controller) && strpos($controller, self::SEPARATOR) !== false) {
            list($controller, $action) = explode(self::SEPARATOR, $controller);
            $response = $this->callClassController($controller, $action);
        } elseif (is_callable($controller)) {
            $response = $this->callCallableController($controller);
        } else {
            throw new AppException(sprintf('Invalid controller type, got "%s"', $this->getType($controller)));
        }

        if (!$response) {
            throw new AppException(sprintf('There was no response returned from the controller handling "%s"', $this->request()->uri(true)));
        }

        if (!$response instanceof ResponseInterface) {
            throw new AppException(sprintf('Invalid response returned from handling "%s", expected ResponseInterface, got "%s"', $this->request()->uri(true), $this->getType($response)));
        }

        return $response;
    }
415876
public function getControllerMiddlewareNext($controller, $method, MiddleWares $middleWares, $decorators)
    {
        return $this->nextClosure($middleWares, function() use ($controller, $method, $decorators) {
            return $this->injectionClass($controller, $method, [], $decorators);
        });
    }
340972
public function initialize(Controller $controller) {
		$this->_controller = $controller;
		if (!$this->_controller->Components->loaded('RequestHandler')) {
			$this->_controller->RequestHandler = $this->_controller->Components->load('RequestHandler');
			$this->_controller->RequestHandler->initialize($this->_controller);
		}
	}
312126
protected function registerInspected($route, $controller, $method, &$names)
    {
        $action = ['uses' => $controller . '@' . $method];
        
        // If a given controller method has been named, we will assign the name to the
        // controller action array, which provides for a short-cut to method naming
        // so you don't have to define an individual route for these controllers.
        $action['as'] = array_get($names, $method);
        $this->{$route['verb']}($route['uri'], $action);
    }
1131908
public function connectMiddlewares($controller, $method, MiddleWares $middleWares, $decorators = [])
    {
        $isClosure = is_callable($controller);
        if ($middleWares->valid()) {
            if ($isClosure) {
                $next = $this->getInvokeMiddlewareNext($controller, $middleWares, $decorators);
            } else {
                $next = $this->getControllerMiddlewareNext($controller, $method, $middleWares, $decorators);
            }
            $middleWares->withNextArgs($next);
            $response = $this->injectionClass($middleWares->current(), 'handle', $middleWares->getNextArgs());
        } else {
            if ($isClosure) {
                $controller = $this->closureBinder($controller);
                $response = $this->injectionClosure($controller, $decorators);
            } else {
                $response = $this->injectionClass($controller, $method, [], $decorators);
            }
        }

        if ($response instanceof Response) {
            $this->sendByResponse($response);
        }
    }
291414
public static function getMiddleware($controller, $method)
    {
        if (! method_exists($controller, 'getMiddleware')) {
            return array();
        }

        $results = array();

        foreach ($controller->getMiddleware() as $middleware => $options) {
            if (static::methodExcludedByOptions($method, $options)) {
                continue;
            }

            $results[] = $middleware;
        }

        return $results;
    }
396669
private function getResourceClosure($controller, $method)
    {
        if ($method == 'show' || $method == 'edit' || $method == 'delete') {
            return function ($id) use ($controller, $method) {
                return $controller::$method($id);
            };
        } elseif ($method == 'update') {
            return function ($request, $id) use ($controller, $method) {
                return $controller::$method($request, $id);
            };
        } elseif ($method == 'insert') {
            return function ($request) use ($controller, $method) {
                return $controller::$method($request);
            };
        } else {
            return function () use ($controller, $method) {
                return $controller::$method();
            };
        }
    }
1339261
protected function collectControllerRoutes(ReflectionClass $controller, array $methods, $prefix)
    {
        $group = new Group;
        $controllerDefaultStrategy = $this->getAnnotatedStrategy($controller);

        foreach ($methods as $method) {
            $name = preg_split("~(?=[A-Z])~", $method->name);
            $http = $name[0];
            unset($name[0]);
 
            if (strpos(Collector::HTTP_METHODS, $http) !== false) {
                $action   = $prefix . strtolower(implode($this->controllerActionJoin, $name));
                $dynamic  = $this->getMethodConstraints($method);
                $strategy = $this->getAnnotatedStrategy($method);

                $route = $this->set($http, "$action$dynamic", [$controller->name, $method->name]);

                if ($strategy !== null) {
                       $route->setStrategy($strategy);
                } else $route->setStrategy($controllerDefaultStrategy);

                $group->set($route);
            }
        }

        return $group;
    }
1024166
function handleActionOrID($request)
    {
        if (is_numeric($request->param('Action'))) {
            $controller = $this->config()->recordController;
            return new $controller($this, $this->getRecordType(), $request);
        } else {
            return $this->handleAction($request, null);
        }
    }
1373376
public function byClassMethod($class, $method)
    {
        $this->controller = new $class();
        $this->controller = is_object($class) ? $class : new $class();
        if ($this->hasContainer() && method_exists($this->controller, 'raikiri'))
            $this->controller->setContainer($this->raikiri());

        $this->action = function() use($method)
        {
            $args = func_get_args();
            return call_user_func_array([$this->controller, $method], $args);
        };
    }
772697
protected function useMethod($class, $method)
    {
        $class = "\\OxApp\\controllers\\" . $class;
        try {
            $controller = new  $class();
        } catch (\Exception $e) {
            throw new \Exception($e);
        }
        if (is_subclass_of($controller, 'Ox\App')) {
            if (!empty($method)) {
                $result = $this->tryRunMethod($controller, $method);
            } else {
                $request = Router::$requestDriver;
                if (!empty($request)) {
                    $result = $this->tryRunMethod($controller, strtolower($request->server->get("REQUEST_METHOD")));
                } else {
                    $result = $this->tryRunMethod($controller, strtolower($_SERVER["REQUEST_METHOD"]));
                }
            }
            $response = new Response(
                $result,
                Response::HTTP_OK
            );
            $response->send();
        } else {
            $this->sandResponseCode(Response::HTTP_METHOD_NOT_ALLOWED);
        }
    }
653809
private function checkMethodExists($method)
    {
        if (! $this->controllerClass->hasMethod($method)) {
            throw new MissingControllerMethodException(
                sprintf(
                    "Method %s::%s() is not defined in controller.",
                    $this->controllerClass->getShortName(),
                    $method
                )
            );
        }
    }
1219300
public function dispatch($method)
	{
		// Save original input.
		$original_input = Request::input();
		
		// Create request.
		$request = Request::create($this->uri, $method, $this->params);
		
		// Replace input (maintain api auth parameters).
		Request::replace(array_merge($request->input(), array(
			'client_id'     => Request::input('client_id'),
			'client_secret' => Request::input('client_secret'),
			'access_token'  => Request::input('access_token'),
		)));
		
		// Dispatch request.
		$response = Route::dispatch($request);
		
		// Restore original input.
		Request::replace($original_input);
		
		$content = $response->getContent();
		return empty($content) ? null : json_decode($response->getContent(), true);
	}