-
-
Save Glavin001/7b118d9c26577891a238acbee150e4d8 to your computer and use it in GitHub Desktop.
Dump all Silex routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/../vendor/autoload.php'; | |
use Symfony\Component\Console\Helper\Table; | |
use Symfony\Component\Console\Output\ConsoleOutput; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Silex\Application; | |
/** | |
* Display all routes registered in a Silex application. | |
* Important: the Silex application must have flushed its controllers before. | |
* | |
* @param Application $app | |
* @param OutputInterface $output | |
*/ | |
function displayRoutes(Application $app, OutputInterface $output = null) { | |
if (null === $output) { | |
$output = new ConsoleOutput(); | |
} | |
$table = new Table($output); | |
$table->setStyle('borderless'); | |
$table->setHeaders(array( | |
'methods', | |
'path' | |
)); | |
foreach ($app['routes'] as $route) { | |
$table->addRow(array( | |
implode('|', $route->getMethods()), | |
$route->getPath(), | |
)); | |
} | |
$table->render(); | |
} | |
// Use it: | |
$silexApp = new Silex\Application(); // Your app | |
// Dont forget: | |
$silexApp->flush(); | |
// Display routes in console: | |
displayRoutes($silexApp); | |
/* Result: | |
$> php list-routes.php | |
========= ======================================== | |
methods path | |
========= ======================================== | |
GET /api/kittens/{id} | |
POST /api/kittens | |
GET /api/users | |
... ... | |
========= ======================================== | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment