예제 #1
0
 /**
  * @throws Exception\ContentTypeNotValidException
  * @throws NotFoundException
  * @throws \Exception
  */
 public function execute()
 {
     $config = $this->config->getConfig();
     // Figure out the route information.
     try {
         $routepath = $this->evaluateRoute();
         $route = $routepath->params;
         $components = $this->determineRouteComponents($route);
         $params = $route;
         unset($params['action']);
         unset($params['responder']);
         unset($params['method']);
     } catch (NotFoundException $e) {
         if (isset($config['error_page']['404'])) {
             $lastRoute = $this->router->getLastRoute();
             $this->eventLog->info(sprintf("No route was found that matches '%s'", $lastRoute));
             $responder = $this->serviceLocator->newInstance($config['error_page']['404']);
             $this->responseManager->process(new Payload(), $responder);
             return;
         }
         // No 404 page was set, so let's throw the exception.
         throw $e;
     }
     // Load the responder that we identified from routes.
     $responder = $this->serviceLocator->newInstance($components['responderClass']);
     // Load the action we identified from routes, if one exists.
     if (!is_null($components['actionClass'])) {
         $action = $this->serviceLocator->newInstance($components['actionClass']);
         if (!is_callable([$action, $components['actionMethod']])) {
             throw new NoValidMethod(sprintf('The method %s does not exist on action %s', $components['actionMethod'], $components['actionClass']));
         }
         // Call the action.
         $result = call_user_func_array([$action, $components['actionMethod']], $params);
     }
     // Let's not leave the response hanging...
     if (!isset($result) || !$result) {
         $result = new Payload();
     }
     // Call and send the response, if possible.
     $this->responseManager->process($result, $responder);
 }
예제 #2
0
 public function __construct(RouteManager $standardRouter)
 {
     $this->router = $standardRouter->getRouter();
 }