src/Helper/Routes.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Helper;
  3. use Symfony\Component\Routing\RouterInterface;
  4. class Routes
  5. {
  6.     private $routes = [];
  7.     public function __construct(RouterInterface $router)
  8.     {
  9.         foreach ($router->getRouteCollection()->all() as $route_name => $route) {
  10.             // if ( $route->getPath()[1] == '_' ) continue;
  11.             // dd( $route );
  12.             $this->routes[$route_name] = [
  13.                 'path' => $route->getPath(),
  14.                 'requirements' => $route->getRequirements(),
  15.                 'defaults' => $route->getDefaults(),
  16.                 'methods' => $route->getMethods(),
  17.             ];
  18.         }
  19.     }
  20.     public function getRoutes(): array
  21.     {
  22.         return $this->routes;
  23.     }
  24. }