Exemplo n.º 1
0
 /**
  * The dispatcher accepts the found route from the route mapper and
  * invokes the correct controller and method.
  *
  * Workflow
  * 1. fetches Route Object
  * 2. extracts info about correct controller, correct method with correct parameters
  * 3. tries to call the method "initializeModule" on the controller
  * 4. finally tries to call the controller with method(parms)!
  *
  * The dispatcher forwards to the pagecontroller = modulecontroller + moduleaction.
  */
 public function forward($request, $response)
 {
     // fetch the target route from the request
     $route = $request->getRoute();
     if ($route === null) {
         throw new \Exception('The dispatcher is unable to forward. No route object given.', 99);
     }
     //$route::debug();
     $classname = $route::getClassname();
     $method = $route::getMethod();
     $parameters = $route::getParameters();
     #$request_meth = Koch_HttpRequest::getRequestMethod();
     #$renderengine = $route::getRenderEngine();
     #$this->event_dispatcher->addEventHandler('onBeforeControllerMethodCall', new Koch_Event_InitializeModule());
     $route::dispatchable();
     $controllerInstance = new $classname($request, $response);
     /**
      * Initialize the Module
      *
      * by calling the "_initializeModule" method on the controller.
      * A module might(!) implement this method for initialization of helper objects.
      *
      * Note the underscore! The method name is intentionally underscored.
      * This places the method on top in the method navigator of your IDE.
      */
     if (true === method_exists($controllerInstance, '_initializeModule')) {
         $controllerInstance->_initializeModule();
     }
     /**
      * "Before Module Filter" is a prefilter on the module controller level.
      *
      *
      * It calls the "_beforeFilter" method on the module controller.
      * A module might(!) implement this method for initialization of helper objects.
      * Example usage: login_required.
      *
      * Note the underscore! The method name is intentionally underscored.
      * This places the method on top in the method navigator of your IDE.
      */
     if (true === method_exists($controllerInstance, '_beforeFilter')) {
         $controllerInstance->_beforeFilter();
     }
     // @todo move into a prefilter / and consider the request being ajax :) = no breadcrumbs
     Breadcrumb::initialize($route->getModuleName(), $route->getSubmoduleName());
     /**
      * Finally: dispatch to the requested controller method
      */
     if (true === method_exists($controllerInstance, $method)) {
         $controllerInstance->{$method}($parameters);
     }
     /**
      * "After Module Filter" is a postfilter on the module controller level.
      *
      * It calls the "_afterFilter" method on the module controller.
      * A module might(!) implement this method for running further processing
      * on reponse data.
      *
      * Note the underscore! The method name is intentionally underscored.
      * This places the method on top in the method navigator of your IDE.
      */
     if (true === method_exists($controllerInstance, '_afterFilter')) {
         $controllerInstance->_afterFilter();
     }
 }
Exemplo n.º 2
0
 /**
  * The dispatcher accepts the found route from the route mapper and
  * invokes the correct controller and method.
  *
  * Workflow
  * 1. fetches Route Object
  * 2. extracts info about correct controller, correct method with correct parameters
  * 3. tries to call the method "initializeModule" on the controller
  * 4. finally tries to call the controller with method(params)!
  *
  * The dispatcher forwards to the pagecontroller = modulecontroller + moduleaction.
  */
 public function forward()
 {
     $route = $this->request->getRoute();
     $classname = $route::getClassname();
     $method = $route::getMethod();
     $parameters = $route::getParameters();
     #$request_meth = \Koch\Http\HttpRequest::getRequestMethod();
     #$renderengine = $route::getRenderEngine();
     #$this->eventDispatcher->addEventHandler('onBeforeControllerMethodCall', new Koch\Event\InitializeModule());
     #\Koch\Debug\Debug::firebug($classname . ' ' . $method . ' ' . var_export($parameters, true));
     $controllerInstance = new $classname($this->request, $this->response);
     /*
      * Initialize the Module
      *
      * by calling the "_initializeModule" method on the controller.
      * A module might(!) implement this method for initialization of helper objects.
      * Basically it's a constructor! Keep it lightweight!
      *
      * Note the underscore! The method name is intentionally underscored.
      * This places the method on top in the method navigator of your IDE.
      */
     if (method_exists($controllerInstance, '_initializeModule')) {
         $controllerInstance->_initializeModule();
     }
     /*
      * "Before Module Filter" is a prefilter on the module controller level.
      *
      * It calls the "_beforeFilter" method on the module controller.
      * A module might(!) implement this method for initialization of helper objects.
      * Example usage: login_required.
      *
      * Note the underscore! The method name is intentionally underscored.
      * This places the method on top in the method navigator of your IDE.
      */
     if (method_exists($controllerInstance, '_beforeModuleFilter')) {
         $controllerInstance->_beforeModeFilter();
     }
     // @todo auto-attach a Module::onBootstrap method as event
     // @todo move into a prefilter / and consider the request being ajax = no breadcrumbs
     Breadcrumb::initialize($route->getModule(), $route->getController());
     /*
      * Finally: dispatch to the requested controller method
      */
     if (method_exists($controllerInstance, $method)) {
         $controllerInstance->{$method}($parameters);
     } else {
         echo 'Class ' . $classname . '->Method ' . $method . ' not found.';
     }
     /*
      * "After Module Filter" is a postfilter on the module controller level.
      *
      * It calls the "_afterFilter" method on the module controller.
      * A module might(!) implement this method for running further processing
      * on reponse data.
      *
      * Note the underscore! The method name is intentionally underscored.
      * This places the method on top in the method navigator of your IDE.
      */
     if (method_exists($controllerInstance, '_afterModuleFilter')) {
         $controllerInstance->_afterModuleFilter();
     }
     // @todo auto-attach a Module::onShutdown method as event
 }