src/CarteBlanche/App/FrontController.php
public function dispatch($controller_classname, $action = 'index', array $arguments = null)
    {
        // load controller
        $_ctrl = CarteBlanche::getContainer()
            ->get('locator')->locateController($controller_classname);
        if (!empty($_ctrl) && class_exists($_ctrl)) {
            $this
                ->setControllerName($_ctrl)
                ->setController(new $_ctrl(CarteBlanche::getContainer()));
        } else {
            throw new \CarteBlanche\Exception\NotFoundException(
                sprintf("Controller '%s' can't be found!", $controller_classname)
            );
        }

        // load action
        if (false===strpos($action, 'Action')) {
            $action .= 'Action';
        }
        $this->setActionName($action);

        // dispatch
        if (method_exists($this->getController(), $this->getActionName())) {
            $result = CodeHelper::fetchArguments(
                $this->getActionName(), $arguments, $this->getController()
            );

            // controller method return treatment
                // string : content
            if (is_string($result)) {
                $this->render(array('output'=>$result));

                // array
            } elseif (is_array($result)) {
                // array : ( output , ... )
                if (isset($result['output'])) {
                    $this->render($result);

                // array : ( view , params )
                } else {
                    $template = $result[0];
                    $params = isset($result[1]) ? $result[1] : array();
                    $content = $this->view($template, $params);
                    if (!empty($content)) {
                        $tpl_params = array('output'=>$content);
                        if (isset($params['title'])) {
                            $tpl_params['title'] = $params['title'];
                        }
                        $this->render($tpl_params);
                    } else {
                        throw new \CarteBlanche\Exception\RuntimeException(
                            sprintf("A controller action must return an array like (view file, params) in [%s -> %s]!",
                                get_class($this->getController()), $this->getActionName())
                        );
                    }
                }

                // response object
            } elseif (is_object($result) && ($result instanceof \CarteBlanche\App\Response)) {
                CarteBlanche::getContainer()->set('response', $return, true);
                $this->render();

                // error
            } else {
                throw new \CarteBlanche\Exception\RuntimeException(
                    sprintf("A controller action must return a string, an array or a response object in [%s -> %s]!",
                        get_class($this->getController()), $this->getActionName())
                );
            }

        } else {
            throw new \CarteBlanche\Exception\NotFoundException(
                sprintf("Action '%s' can't be found in controller '%s'!", $this->getActionName(), get_class($this->getController()))
            );
        }
    }
public function dispatch($controller_classname, $action = 'index', array $arguments = null)
    {
        // load controller
        $_ctrl = CarteBlanche::getContainer()
            ->get('locator')->locateController($controller_classname);
        if (!empty($_ctrl) && class_exists($_ctrl)) {
            $this
                ->setControllerName($_ctrl)
                ->setController(new $_ctrl(CarteBlanche::getContainer()));
        } else {
            throw new \CarteBlanche\Exception\NotFoundException(
                sprintf("Controller '%s' can't be found!", $controller_classname)
            );
        }

        // load action
        if (false===strpos($action, 'Action')) {
            $action .= 'Action';
        }
        $this->setActionName($action);

        // dispatch
        if (method_exists($this->getController(), $this->getActionName())) {
            $result = CodeHelper::fetchArguments(
                $this->getActionName(), $arguments, $this->getController()
            );

            // controller method return treatment
                // string : content
            if (is_string($result)) {
                $this->render(array('output'=>$result));

                // array
            } elseif (is_array($result)) {
                // array : ( output , ... )
                if (isset($result['output'])) {
                    $this->render($result);

                // array : ( view , params )
                } else {
                    $template = $result[0];
                    $params = isset($result[1]) ? $result[1] : array();
                    $content = $this->view($template, $params);
                    if (!empty($content)) {
                        $tpl_params = array('output'=>$content);
                        if (isset($params['title'])) {
                            $tpl_params['title'] = $params['title'];
                        }
                        $this->render($tpl_params);
                    } else {
                        throw new \CarteBlanche\Exception\RuntimeException(
                            sprintf("A controller action must return an array like (view file, params) in [%s -> %s]!",
                                get_class($this->getController()), $this->getActionName())
                        );
                    }
                }

                // response object
            } elseif (is_object($result) && ($result instanceof \CarteBlanche\App\Response)) {
                CarteBlanche::getContainer()->set('response', $return, true);
                $this->render();

                // error
            } else {
                throw new \CarteBlanche\Exception\RuntimeException(
                    sprintf("A controller action must return a string, an array or a response object in [%s -> %s]!",
                        get_class($this->getController()), $this->getActionName())
                );
            }

        } else {
            throw new \CarteBlanche\Exception\NotFoundException(
                sprintf("Action '%s' can't be found in controller '%s'!", $this->getActionName(), get_class($this->getController()))
            );
        }
    }
Dispatch a controller's action, passing it arguments

@param   string      $controller_classname
@param   string      $action
@param   array|null  $arguments
@return  void
@throws  \CarteBlanche\Exception\NotFoundException if the controller or the action is not found
@throws  \CarteBlanche\Exception\RuntimeException if the controller's action doesn't return required objects