コード例 #1
0
ファイル: Router.php プロジェクト: pavelkolomitkin/nigma-blog
 /**
  * Возвращает объект типа Route, соответствующий запросу $request. Если маршрут не найден, то генерируется исключение
  * RouteNotFoundException
  * @param Request $request
  * @return Route
  */
 public function getRouteByRequest(Request $request)
 {
     $result = null;
     $path = $request->getPath();
     foreach ($this->routes as $name => $route) {
         if ($route->isPathEquivalent($path)) {
             $result = $route;
             break;
         }
     }
     if (!$result) {
         throw new RouteNotFoundException('Route by path "' . $path . '" does not exist');
     }
     if (!empty($result->getAllowHttpMethods()) && !in_array($request->getMethod(), $result->getAllowHttpMethods())) {
         throw new RouteNotFoundException('Route by path "' . $path . '" does not exist');
     }
     return $result;
 }