public function dispatch($router)
    {
        $context = $this->_context;

        if ($router instanceof RouterContext) {
            $area = $router->area;
            $controller = $router->controller;
            $action = $router->action;
            $params = $router->params;
        } else {
            $area = $router->getArea();
            $controller = $router->getController();
            $action = $router->getAction();
            $params = $router->getParams();
        }

        if ($area) {
            $area = strpos($area, '_') === false ? ucfirst($area) : Text::camelize($area);
            $context->area = $area;
        }

        $controller = strpos($controller, '_') === false ? ucfirst($controller) : Text::camelize($controller);
        $context->controller = $controller;

        $action = strpos($action, '_') === false ? $action : lcfirst(Text::camelize($action));
        $context->action = $action;

        $context->params = $params;

        if ($area) {
            if ($action === 'index') {
                if ($controller === 'Index') {
                    $context->path = $area === 'Index' ? '/' : '/' . Text::underscore($area);
                } else {
                    $context->path = '/' . Text::underscore($area) . '/' . Text::underscore($controller);
                }
            } else {
                $context->path = '/' . Text::underscore($area) . '/' . Text::underscore($controller) . '/' . Text::underscore($action);
            }
        } else {
            if ($action === 'index') {
                $context->path = $controller === 'Index' ? '/' : '/' . Text::underscore($controller);
            } else {
                $context->path = '/' . Text::underscore($controller) . '/' . Text::underscore($action);
            }
        }

        $controllerClassName = $this->_getControllerClassName();

        /**
         * @var \ManaPHP\Rest\Controller $controllerInstance
         */
        $controllerInstance = $this->_di->getShared($controllerClassName);
        $context->controllerInstance = $controllerInstance;

        return $this->invokeAction($controllerInstance, $action, $params);
    }