Add routes dumper

This commit is contained in:
Romain Neutron
2013-05-30 20:09:31 +02:00
parent 7137979fd4
commit a4779d7e55
2 changed files with 60 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
use Alchemy\Phrasea\CLI; use Alchemy\Phrasea\CLI;
use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Command\Developer\RegenerateSqliteDb; use Alchemy\Phrasea\Command\Developer\RegenerateSqliteDb;
use Alchemy\Phrasea\Command\Developer\RoutesDumper;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
@@ -60,6 +61,7 @@ try {
} }
$cli->command(new RegenerateSqliteDb()); $cli->command(new RegenerateSqliteDb());
$cli->command(new RoutesDumper());
$cli['console']->addCommands(array( $cli['console']->addCommands(array(
// DBAL Commands // DBAL Commands

View File

@@ -0,0 +1,58 @@
<?php
namespace Alchemy\Phrasea\Command\Developer;
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class RoutesDumper extends Command
{
public function __construct()
{
parent::__construct('routes:dump');
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$result = 0;
$maxNameLength = 0;
$maxMethodsLength = 0;
$data = array();
foreach ($this->container['routes'] as $name => $route) {
$methods = implode('|', $route->getMethods());
$pattern = $route->getPattern();
$warning = false;
$maxNameLength = max($maxNameLength, strlen($name));
$maxMethodsLength = max($maxMethodsLength, strlen($methods));
if (0 === strpos($name, '_')) {
$result++;
$warning = true;
}
$data[] = array(
'name' => $name,
'methods' => $methods ?: 'ALL',
'pattern' => $pattern,
'warning' => $warning
);
}
foreach ($data as $route) {
$line = sprintf('%-'.$maxMethodsLength.'s %-'.$maxNameLength.'s %s', $route['methods'], $route['name'], $route['pattern']);
if ($route['warning']) {
$line = str_replace(' '.$route['name'].' ', ' <comment>'.$route['name'].'</comment> ', $line);
}
$output->writeln($line);
}
return $result;
}
}