mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Add routes dumper
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
use Alchemy\Phrasea\CLI;
|
||||
use Alchemy\Phrasea\Core\Version;
|
||||
use Alchemy\Phrasea\Command\Developer\RegenerateSqliteDb;
|
||||
use Alchemy\Phrasea\Command\Developer\RoutesDumper;
|
||||
|
||||
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
|
||||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
||||
@@ -60,6 +61,7 @@ try {
|
||||
}
|
||||
|
||||
$cli->command(new RegenerateSqliteDb());
|
||||
$cli->command(new RoutesDumper());
|
||||
|
||||
$cli['console']->addCommands(array(
|
||||
// DBAL Commands
|
||||
|
58
lib/Alchemy/Phrasea/Command/Developer/RoutesDumper.php
Normal file
58
lib/Alchemy/Phrasea/Command/Developer/RoutesDumper.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user