Example #1
0
 /**
  * @throws ControllerException
  */
 protected function processDispatch()
 {
     $controllerEvent = new ControllerEvent($this);
     $this->eventDispatcher->dispatch(MvcEvent::ON_CONTROLLER_DISPATCH, $controllerEvent);
     if ($controllerEvent->hasResponse()) {
         $this->response = $controllerEvent->getResponse();
         return;
     }
     $actionMethod = $this->getActionMethod();
     if (method_exists($this, $actionMethod)) {
         $response = call_user_func(array($this, $actionMethod));
         if ($response) {
             $this->response = $response;
         }
         return;
     }
     $moduleName = $this->request->getModuleName();
     $controllerName = $this->request->getControllerName();
     throw new ControllerException("The controller {$controllerName} (module: {$moduleName}) does not implement method {$actionMethod}!");
 }
Example #2
0
 /**
  * loads controller class
  *
  * @throws HttpKernelException
  * @return string
  */
 protected function loadControllerClass()
 {
     $moduleName = $this->request->getModuleName();
     $controllerName = $this->request->getControllerName();
     // fully qualified controller class name
     $fullQualifiedClassName = $this->getControllerClassName($moduleName, $controllerName);
     // load controller class
     if (!class_exists($fullQualifiedClassName, false)) {
         // relative controller class name (without namespace)
         $posLastBackslash = strrpos($fullQualifiedClassName, '\\');
         // class name
         $className = substr($fullQualifiedClassName, $posLastBackslash + 1);
         // path to controller classes for that module
         $controllerPath = $this->getControllerPath($moduleName, $controllerName);
         // controller class file
         $classFile = $controllerPath . DIRECTORY_SEPARATOR . $className . '.php';
         if (!is_file($classFile)) {
             throw new HttpKernelException("Could not find file '{$classFile}' for class '{$fullQualifiedClassName}'!");
         }
         /** @noinspection PhpIncludeInspection */
         require_once $classFile;
     }
     return $fullQualifiedClassName;
 }
Example #3
0
 /**
  * sets template path by request
  *
  * @param RequestInterface $request
  */
 public function setTemplatePathByRequest(RequestInterface $request)
 {
     $params = array('action' => $request->getActionName(), 'controller' => $request->getControllerName(), 'module' => $request->getModuleName());
     $templatePath = Util::parsePattern($this->viewPathPattern, $params);
     $this->getRenderer()->setTemplatePath($templatePath);
 }