Skip to content

Instantly share code, notes, and snippets.

@dfritschy
Created December 4, 2018 17:54
Show Gist options
  • Save dfritschy/57d9c009037f021fa706fc4060e5d14a to your computer and use it in GitHub Desktop.
Save dfritschy/57d9c009037f021fa706fc4060e5d14a to your computer and use it in GitHub Desktop.
Dump Symfony Routes to yaml File
/**
* Dump Routes to YAML File.
*/
public function dumpRoutes()
{
/** @var $router \Symfony\Component\Routing\Router */
$router = $this->container->get('router');
$collection = $router->getRouteCollection();
$allRoutes = $collection->all();
array_multisort($allRoutes);
$output = [];
/** @var @Route $route */
foreach ($allRoutes as $name => $route) {
if (substr($name, 0, 1) !== "_") {
$output[] = "$name:";
$output[] = " path: " . $route->getPath();
$output[] = " controller: " . $route->getDefault('_controller');
$output[] = "";
}
}
file_put_contents('output.yaml', implode("\n", $output));
return new Response('done');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment