/** * Checks whether the request matches with this route * * @param \Pushy\Network\Http\RequestData $request The request to match * * @return boolean True when the route matches the request */ public function doesRequestMatch(RequestData $request) { return $this->doesMethodMatch($request->getMethod()) && $this->doesPathMatch($request->getPath()); }
/** * Gets the route based on the current request * * When no route matches it tries to load the 404 route. When that also is not defined it will throw up. * * @param \Pushy\Network\Http\RequestData $request The request object * * @return \Pushy\Router\AccessPoint The matching route * @throws \Pushy\Router\NoMatchingRouteException When no route matches and no 404 route exists */ public function getRouteByRequest(RequestData $request) { foreach ($this->routes[$request->getMethod()] as $route) { if ($route->doesRequestMatch($request)) { return $route; } } if (array_key_exists('404', $this->routes['GET'])) { return $this->routes['GET']['404']; } throw new NoMatchingRouteException('Found no matching route for the current request.'); }