getController() public method

Get the currently registered controller name
public getController ( ) : string
return string
Exemplo n.º 1
0
 /**
  *
  */
 public function handleError(MvcEvent $event)
 {
     $controller = $event->getController();
     $error = $event->getParam('error');
     $exception = $event->getParam('exception');
     $message = sprintf('Error dispatching controller "%s". Error was: "%s"', $controller, $error);
     if ($exception instanceof \Exception) {
         $message .= ', Exception(' . $exception->getMessage() . '): ' . $exception->getTraceAsString();
     }
     error_log($message);
 }
Exemplo n.º 2
0
 /**
  * Inject the controller and controller class into the model
  *
  * If either $displayExceptions or $displayNotFoundReason are enabled,
  * injects the controllerClass from the MvcEvent. It checks to see if a
  * controller is present in the MvcEvent, and, if not, grabs it from
  * the route match if present; if a controller is found, it injects it into
  * the model.
  *
  * @param  ViewModel $model
  * @param  MvcEvent $e
  * @return void
  */
 protected function injectController($model, $e)
 {
     if (!$this->displayExceptions() && !$this->displayNotFoundReason()) {
         return;
     }
     $controller = $e->getController();
     if (empty($controller)) {
         $routeMatch = $e->getRouteMatch();
         if (empty($routeMatch)) {
             return;
         }
         $controller = $routeMatch->getParam('controller', false);
         if (!$controller) {
             return;
         }
     }
     $controllerClass = $e->getControllerClass();
     $model->setVariable('controller', $controller);
     $model->setVariable('controller_class', $controllerClass);
 }
Exemplo n.º 3
0
 /**
  * General dispatch listener
  *
  * @param \Zend\Mvc\MvcEvent $event
  */
 public function onDispatch(MvcEvent $event)
 {
     if ($this->response) {
         $event->stopPropagation();
         return $this->response;
     }
     $routeMatch = $event->getRouteMatch();
     $sm = $event->getApplication()->getServiceManager();
     // Set current timezone, when first get
     $sm->get('Timezone');
     if ($routeMatch) {
         $locale = $routeMatch->getParam('locale');
     }
     if (!$locale) {
         $request = $event->getRequest();
         if ($request instanceof HttpRequest) {
             $header = $request->getHeader('Accept-Language');
             if ($header) {
                 $availables = null;
                 $controller = $event->getController();
                 if ($controller instanceof LocaleSelectorInterface) {
                     $availables = $controller->getAvailableLocales();
                 }
                 $locale = $sm->get('Locale')->acceptFromHttp($header->getFieldValue(), $availables);
             }
         }
     }
     if ($locale) {
         $sm->get('Locale')->setCurrent($locale);
     }
 }
Exemplo n.º 4
0
 public function detectError(MvcEvent $event)
 {
     $result = $event->getResult();
     if ($result instanceof ResponseInterface) {
         // Already have a response as the result
         return;
     }
     $error = $event->getError();
     $ex = $event->getParam('exception');
     switch ($error) {
         case Application::ERROR_CONTROLLER_NOT_FOUND:
             $message = ucfirst($event->getControllerClass());
             $ex = new RdnException\RuntimeException($message, 500, $ex);
             break;
         case Application::ERROR_CONTROLLER_INVALID:
             $message = $event->getController() . ' is not dispatchable';
             $ex = new RdnException\RuntimeException($message, 500, $ex);
             break;
         case Application::ERROR_ROUTER_NO_MATCH:
             $message = 'Request did not match any routes.';
             $ex = new RdnException\NotFoundException($message, 404, $ex);
             break;
     }
     if (isset($message)) {
         if ($ex->getCode() == 500) {
             $event->setError(Application::ERROR_EXCEPTION);
         }
         $event->setParam('exception', $ex);
     }
 }