Example #1
0
 /**
  * Determine the matched route from either the router or namedRoute
  * @param  string|null                       $namedRoute
  * @param  array                             $routeParams
  * @throws Route\NoMatchException|\Exception
  * @return RouteMetaData|bool                $route - if false no route could be matched
  *                                                       (ideally the response should be returned in this instance - fail fast)
  */
 protected function determineRoute($namedRoute = null, array $routeParams = array())
 {
     // dispatch preRoutingAction event
     $this->getEventManager()->dispatchEvent(Event\Events::PRE_ROUTING, new Event\PreRoutingArgs($this->service));
     try {
         $route = !is_null($namedRoute) ? $this->getNamedRoute($namedRoute, $routeParams) : $this->getMatchedRoute(true);
     } catch (\Exception $e) {
         // dispatch postRoutingAction event
         $this->getEventManager()->dispatchEvent(Event\Events::POST_ROUTING, new Event\PostRoutingArgs($this->service));
         if ($e instanceof NoMatchException && ($this->doCGOptionsCheck() || $this->doOptionsCheck())) {
             return false;
         }
         throw $e;
     }
     // dispatch postRoutingAction event
     $this->getEventManager()->dispatchEvent(Event\Events::POST_ROUTING, new Event\PostRoutingArgs($this->service));
     // Set parameters matched on the route to the request object
     $this->request->setRouteParam($route->getRouteParams());
     return $route;
 }