public function dispatch(Route $route)
    {
        do {
            $this->getEventManager()->publish("pre.dispatch", array($route, $this));

            $protoView = $this->_view->cloneThis();
            $controllerClassName = $route->getControllerName() . "Controller";
            $action = $route->getActionName() . "Action";
            $classPath = $this->getControllerPath() . DIRECTORY_SEPARATOR . $controllerClassName . ".php";
            $viewPath = $route->getControllerPath()
                . DIRECTORY_SEPARATOR
                . $route->getActionPath()
                . $protoView->getViewExt();

            if (!file_exists($classPath)) {
                // Use base controller
                $controllerClassName = 'Controller';
            } else {
                require_once $classPath;
            }

            $controller = new $controllerClassName($this);
            $controller->setRouter($this->getRouter());
            $controller->setRequest($this->getRequest());
            $controller->setParams(
                array_merge(
                    array(
                        "dispatcher" => $this,
                        "bootstrap" => $this->getBootstrap()
                    ),
                    $route->getParams()));
            $controller->setRawBody(@file_get_contents('php://input'));

            $controller->setView($protoView->cloneThis());
            $controller->view->controllerPath = $this->getControllerPath();

            if (method_exists($controller, $action)) {
                ob_start();
                $controller->init();
                $controller->$action();
                array_push($this->_viewsQueue, ob_get_contents());
                ob_end_clean();
            } else {
                if (!file_exists($controller->view->getViewPath() . DIRECTORY_SEPARATOR . $viewPath)) {
                    throw new RuntimeException("Page not found {$route->getControllerName()} -> {$route->getActionName()}", 404);
                }
            }

            if ($controller->view->getViewPath()) {
                array_push(
                    $this->_viewsQueue,
                    $controller->getView()->render(
                        (($controller->getViewPath() !== false) ? $controller->getViewPath() : $viewPath))
                );
            }

            $this->getEventManager()->publish("post.dispatch", array($this));
        } while(($route = array_shift($this->_actions)));

        return implode("", $this->_viewsQueue);
    }
public function dispatch(Route $route)
    {
        do {
            $this->getEventManager()->publish("pre.dispatch", array($route, $this));

            $protoView = $this->_view->cloneThis();
            $controllerClassName = $route->getControllerName() . "Controller";
            $action = $route->getActionName() . "Action";
            $classPath = $this->getControllerPath() . DIRECTORY_SEPARATOR . $controllerClassName . ".php";
            $viewPath = $route->getControllerPath()
                . DIRECTORY_SEPARATOR
                . $route->getActionPath()
                . $protoView->getViewExt();

            if (!file_exists($classPath)) {
                // Use base controller
                $controllerClassName = 'Controller';
            } else {
                require_once $classPath;
            }

            $controller = new $controllerClassName($this);
            $controller->setRouter($this->getRouter());
            $controller->setRequest($this->getRequest());
            $controller->setParams(
                array_merge(
                    array(
                        "dispatcher" => $this,
                        "bootstrap" => $this->getBootstrap()
                    ),
                    $route->getParams()));
            $controller->setRawBody(@file_get_contents('php://input'));

            $controller->setView($protoView->cloneThis());
            $controller->view->controllerPath = $this->getControllerPath();

            if (method_exists($controller, $action)) {
                ob_start();
                $controller->init();
                $controller->$action();
                array_push($this->_viewsQueue, ob_get_contents());
                ob_end_clean();
            } else {
                if (!file_exists($controller->view->getViewPath() . DIRECTORY_SEPARATOR . $viewPath)) {
                    throw new RuntimeException("Page not found {$route->getControllerName()} -> {$route->getActionName()}", 404);
                }
            }

            if ($controller->view->getViewPath()) {
                array_push(
                    $this->_viewsQueue,
                    $controller->getView()->render(
                        (($controller->getViewPath() !== false) ? $controller->getViewPath() : $viewPath))
                );
            }

            $this->getEventManager()->publish("post.dispatch", array($this));
        } while(($route = array_shift($this->_actions)));

        return implode("", $this->_viewsQueue);
    }
public function dispatch ( Route $ route ) { do { $ this -> getEventManager ( ) -> publish ( "pre.dispatch" , array ( $ route , $ this ) ) ; $ protoView = $ this -> _view -> cloneThis ( ) ; $ controllerClassName = $ route -> getControllerName ( ) . "Controller" ; $ action = $ route -> getActionName ( ) . "Action" ; $ classPath = $ this -> getControllerPath ( ) . DIRECTORY_SEPARATOR . $ controllerClassName . ".php" ; $ viewPath = $ route -> getControllerPath ( ) . DIRECTORY_SEPARATOR . $ route -> getActionPath ( ) . $ protoView -> getViewExt ( ) ; if ( ! file_exists ( $ classPath ) ) { // Use base controller $ controllerClassName = 'Controller' ; } else { require_once $ classPath ; } $ controller = new $ controllerClassName ( $ this ) ; $ controller -> setRouter ( $ this -> getRouter ( ) ) ; $ controller -> setRequest ( $ this -> getRequest ( ) ) ; $ controller -> setParams ( array_merge ( array ( "dispatcher" => $ this , "bootstrap" => $ this -> getBootstrap ( ) ) , $ route -> getParams ( ) ) ) ; $ controller -> setRawBody ( @ file_get_contents ( 'php://input' ) ) ; $ controller -> setView ( $ protoView -> cloneThis ( ) ) ; $ controller -> view -> controllerPath = $ this -> getControllerPath ( ) ; if ( method_exists ( $ controller , $ action ) ) { ob_start ( ) ; $ controller -> init ( ) ; $ controller -> $ action ( ) ; array_push ( $ this -> _viewsQueue , ob_get_contents ( ) ) ; ob_end_clean ( ) ; } else { if ( ! file_exists ( $ controller -> view -> getViewPath ( ) . DIRECTORY_SEPARATOR . $ viewPath ) ) { throw new RuntimeException ( "Page not found {$route->getControllerName()} -> {$route->getActionName()}" , 404 ) ; } } if ( $ controller -> view -> getViewPath ( ) ) { array_push ( $ this -> _viewsQueue , $ controller -> getView ( ) -> render ( ( ( $ controller -> getViewPath ( ) !== false ) ? $ controller -> getViewPath ( ) : $ viewPath ) ) ) ; } $ this -> getEventManager ( ) -> publish ( "post.dispatch" , array ( $ this ) ) ; } while ( ( $ route = array_shift ( $ this -> _actions ) ) ) ; return implode ( "" , $ this -> _viewsQueue ) ; }
dispatch an action
dispatch an action