/** * Gets a route by name. * * @param string $name The route name * * @return Route|null A Route instance or null when not found */ public function get($name) { try { return $this->provider->getRouteByName($name); } catch (RouteNotFoundException $e) { return null; } }
/** * {@inheritdoc} */ public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { if ($name instanceof SymfonyRoute) { $route = $name; } elseif (null === ($route = $this->provider->getRouteByName($name))) { throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name)); } // the Route has a cache of its own and is not recompiled as long as it does not get modified $compiledRoute = $route->compile(); $hostTokens = $compiledRoute->getHostTokens(); $debug_message = $this->getRouteDebugMessage($name); return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $debug_message, $referenceType, $hostTokens); }
/** * Tries to handle the options request. * * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event * The request event. */ public function onRequest(GetResponseEvent $event) { if ($event->getRequest()->isMethod('OPTIONS')) { $routes = $this->routeProvider->getRouteCollectionForRequest($event->getRequest()); // In case we don't have any routes, a 403 should be thrown by the normal // request handling. if (count($routes) > 0) { $methods = array_map(function (Route $route) { return $route->getMethods(); }, $routes->all()); // Flatten and unique the available methods. $methods = array_unique(call_user_func_array('array_merge', $methods)); $response = new Response('', 200, ['Allow' => implode(', ', $methods)]); $event->setResponse($response); } } }
/** * {@inheritdoc} */ public function matchRequest(Request $request) { $collection = $this->routeProvider->getRouteCollectionForRequest($request); if (!count($collection)) { throw new ResourceNotFoundException(); } // Route filters are expected to throw an exception themselves if they // end up filtering the list down to 0. foreach ($this->getRouteFilters() as $filter) { $collection = $filter->filter($collection, $request); } $attributes = $this->finalMatcher->finalMatch($collection, $request); return $attributes; }