Inside a console.php file :

# php
require_once __DIR__.'/vendor/autoload.php';

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\TableHelper;

$console = new Application('Silex Console', '1.0.0');

// ...require $app...
$app->boot();
$app->flush();

// Define some formatter output
$table = $console->getHelperSet()->get('table');
$table->setHeaders(array('Name', 'Path', 'Requirements'));
$table->setLayout(TableHelper::LAYOUT_DEFAULT); // Different layout exists; this is the default

$console
    ->register('router:debug')
    ->setDescription('Dumps all the routes with their name, path and requirements')
    ->setCode(function(InputInterface $input, OutputInterface $output) use ($app, $table) {
        $routes    = $app['routes'];
        foreach ($routes as $name => $route) {
            $requirements = array();
            foreach ($route->getRequirements() as $key => $requirement) {
                $requirements[] = $key . ' => ' . $requirement;
            }

            $table->addRow(array(
                $name,
                $route->getPath(),
                join(', ', $requirements)
            ));
        }

        $table->render($output);
    })
;

Created on 02-09-2014 by Eric le bihen

comments powered by Disqus