Symfony\Component\Routing\RouteCollection::get PHP Method

get() public method

Gets a route by name.
public get ( string $name ) : Symfony\Component\Routing\Route
$name string The route name
return Symfony\Component\Routing\Route $route A Route instance
    public function get($name)
    {
        return isset($this->routes[$name]) ? $this->routes[$name] : null;
    }

Same methods

RouteCollection::get ( string $name ) : Symfony\Component\Routing\Route | null

Usage Example

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $e
  */
 public function onKernelView(GetResponseForControllerResultEvent $e)
 {
     $queryset = $e->getControllerResult();
     $routeName = $e->getRequest()->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $interface = 'SDispatcher\\Common\\PaginatorInterface';
     $paginatorClass = $route->getOption(RouteOptions::PAGINATOR_CLASS);
     if (!$paginatorClass || !is_subclass_of($paginatorClass, $interface)) {
         return;
     }
     try {
         /* @var \SDispatcher\Common\PaginatorInterface $paginator */
         $paginator = new $paginatorClass();
         if (!$paginator->supports($queryset)) {
             return;
         }
         list($headers, $data) = $paginator->paginate($e->getRequest(), $queryset, 0, $route->getOption(RouteOptions::PAGE_LIMIT), $route->getOption(RouteOptions::PAGINATED_META_CONTAINER_NAME), $route->getOption(RouteOptions::PAGINATED_DATA_CONTAINER_NAME));
     } catch (\Exception $ex) {
         list($headers, $data) = array(array(), array());
     }
     $response = new DataResponse($data);
     $response->headers->add($headers);
     $e->setResponse($response);
 }
All Usage Examples Of Symfony\Component\Routing\RouteCollection::get