Applied the new styles to the router: commands
This commit is contained in:
parent
078f953935
commit
13d0da26fd
@ -15,6 +15,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper;
|
use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper;
|
||||||
use Symfony\Component\Routing\RouterInterface;
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
|
|
||||||
@ -74,9 +75,11 @@ EOF
|
|||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$formatter = $this->getHelper('formatter');
|
$output = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$output->writeln($formatter->formatSection('warning', 'The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0', 'comment'));
|
$output->title('Router Apache Dumper');
|
||||||
|
|
||||||
|
$output->caution('The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0.');
|
||||||
|
|
||||||
$router = $this->getContainer()->get('router');
|
$router = $this->getContainer()->get('router');
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Routing\RouterInterface;
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
use Symfony\Component\Routing\Route;
|
use Symfony\Component\Routing\Route;
|
||||||
|
|
||||||
@ -77,8 +78,10 @@ EOF
|
|||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
$output = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
if (false !== strpos($input->getFirstArgument(), ':d')) {
|
if (false !== strpos($input->getFirstArgument(), ':d')) {
|
||||||
$output->writeln('<comment>The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.</comment>');
|
$output->caution('The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $input->getArgument('name');
|
$name = $input->getArgument('name');
|
||||||
@ -89,11 +92,14 @@ EOF
|
|||||||
if (!$route) {
|
if (!$route) {
|
||||||
throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
|
throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->convertController($route);
|
$this->convertController($route);
|
||||||
|
|
||||||
$helper->describe($output, $route, array(
|
$helper->describe($output, $route, array(
|
||||||
'format' => $input->getOption('format'),
|
'format' => $input->getOption('format'),
|
||||||
'raw_text' => $input->getOption('raw'),
|
'raw_text' => $input->getOption('raw'),
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
'output' => $output,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$routes = $this->getContainer()->get('router')->getRouteCollection();
|
$routes = $this->getContainer()->get('router')->getRouteCollection();
|
||||||
@ -106,6 +112,7 @@ EOF
|
|||||||
'format' => $input->getOption('format'),
|
'format' => $input->getOption('format'),
|
||||||
'raw_text' => $input->getOption('raw'),
|
'raw_text' => $input->getOption('raw'),
|
||||||
'show_controllers' => $input->getOption('show-controllers'),
|
'show_controllers' => $input->getOption('show-controllers'),
|
||||||
|
'output' => $output,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Routing\RouterInterface;
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
|
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
|
||||||
|
|
||||||
@ -75,6 +76,8 @@ EOF
|
|||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
$output = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$router = $this->getContainer()->get('router');
|
$router = $this->getContainer()->get('router');
|
||||||
$context = $router->getContext();
|
$context = $router->getContext();
|
||||||
if (null !== $method = $input->getOption('method')) {
|
if (null !== $method = $input->getOption('method')) {
|
||||||
@ -91,25 +94,26 @@ EOF
|
|||||||
|
|
||||||
$traces = $matcher->getTraces($input->getArgument('path_info'));
|
$traces = $matcher->getTraces($input->getArgument('path_info'));
|
||||||
|
|
||||||
|
$output->newLine();
|
||||||
|
|
||||||
$matches = false;
|
$matches = false;
|
||||||
foreach ($traces as $trace) {
|
foreach ($traces as $trace) {
|
||||||
if (TraceableUrlMatcher::ROUTE_ALMOST_MATCHES == $trace['level']) {
|
if (TraceableUrlMatcher::ROUTE_ALMOST_MATCHES == $trace['level']) {
|
||||||
$output->writeln(sprintf('<fg=yellow>Route "%s" almost matches but %s</>', $trace['name'], lcfirst($trace['log'])));
|
$output->text(sprintf('Route <info>"%s"</> almost matches but %s', $trace['name'], lcfirst($trace['log'])));
|
||||||
} elseif (TraceableUrlMatcher::ROUTE_MATCHES == $trace['level']) {
|
} elseif (TraceableUrlMatcher::ROUTE_MATCHES == $trace['level']) {
|
||||||
$output->writeln(sprintf('<fg=green>Route "%s" matches</>', $trace['name']));
|
$output->success(sprintf('Route "%s" matches', $trace['name']));
|
||||||
|
|
||||||
$routerDebugcommand = $this->getApplication()->find('debug:router');
|
$routerDebugCommand = $this->getApplication()->find('debug:router');
|
||||||
$output->writeln('');
|
$routerDebugCommand->run(new ArrayInput(array('name' => $trace['name'])), $output);
|
||||||
$routerDebugcommand->run(new ArrayInput(array('name' => $trace['name'])), $output);
|
|
||||||
|
|
||||||
$matches = true;
|
$matches = true;
|
||||||
} elseif ($input->getOption('verbose')) {
|
} elseif ($input->getOption('verbose')) {
|
||||||
$output->writeln(sprintf('Route "%s" does not match: %s', $trace['name'], $trace['log']));
|
$output->text(sprintf('Route "%s" does not match: %s', $trace['name'], $trace['log']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$matches) {
|
if (!$matches) {
|
||||||
$output->writeln(sprintf('<fg=red>None of the routes match the path "%s"</>', $input->getArgument('path_info')));
|
$output->error(sprintf('None of the routes match the path "%s"', $input->getArgument('path_info')));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,13 @@ class TextDescriptor extends Descriptor
|
|||||||
protected function describeRouteCollection(RouteCollection $routes, array $options = array())
|
protected function describeRouteCollection(RouteCollection $routes, array $options = array())
|
||||||
{
|
{
|
||||||
$showControllers = isset($options['show_controllers']) && $options['show_controllers'];
|
$showControllers = isset($options['show_controllers']) && $options['show_controllers'];
|
||||||
$headers = array('Name', 'Method', 'Scheme', 'Host', 'Path');
|
|
||||||
$table = new Table($this->getOutput());
|
|
||||||
$table->setStyle('compact');
|
|
||||||
$table->setHeaders($showControllers ? array_merge($headers, array('Controller')) : $headers);
|
|
||||||
|
|
||||||
|
$tableHeaders = array('Name', 'Method', 'Scheme', 'Host', 'Path');
|
||||||
|
if ($showControllers) {
|
||||||
|
$tableHeaders[] = 'Controller';
|
||||||
|
}
|
||||||
|
|
||||||
|
$tableRows = array();
|
||||||
foreach ($routes->all() as $name => $route) {
|
foreach ($routes->all() as $name => $route) {
|
||||||
$row = array(
|
$row = array(
|
||||||
$name,
|
$name,
|
||||||
@ -58,12 +60,17 @@ class TextDescriptor extends Descriptor
|
|||||||
$row[] = $controller;
|
$row[] = $controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->addRow($row);
|
$tableRows[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writeText($this->formatSection('router', 'Current routes')."\n", $options);
|
if (isset($options['output'])) {
|
||||||
|
$options['output']->table($tableHeaders, $tableRows);
|
||||||
|
} else {
|
||||||
|
$table = new Table($this->getOutput());
|
||||||
|
$table->setHeaders($tableHeaders)->setRows($tableRows);
|
||||||
$table->render();
|
$table->render();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@ -73,26 +80,24 @@ class TextDescriptor extends Descriptor
|
|||||||
$requirements = $route->getRequirements();
|
$requirements = $route->getRequirements();
|
||||||
unset($requirements['_scheme'], $requirements['_method']);
|
unset($requirements['_scheme'], $requirements['_method']);
|
||||||
|
|
||||||
// fixme: values were originally written as raw
|
$tableHeaders = array('Property', 'Value');
|
||||||
$description = array(
|
$tableRows = array(
|
||||||
'<comment>Path</comment> '.$route->getPath(),
|
array('Route Name', $options['name']),
|
||||||
'<comment>Path Regex</comment> '.$route->compile()->getRegex(),
|
array('Path', $route->getPath()),
|
||||||
'<comment>Host</comment> '.('' !== $route->getHost() ? $route->getHost() : 'ANY'),
|
array('Path Regex', $route->compile()->getRegex()),
|
||||||
'<comment>Host Regex</comment> '.('' !== $route->getHost() ? $route->compile()->getHostRegex() : ''),
|
array('Host', ('' !== $route->getHost() ? $route->getHost() : 'ANY')),
|
||||||
'<comment>Scheme</comment> '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'),
|
array('Host Regex', ('' !== $route->getHost() ? $route->compile()->getHostRegex() : '')),
|
||||||
'<comment>Method</comment> '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'),
|
array('Scheme', ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY')),
|
||||||
'<comment>Class</comment> '.get_class($route),
|
array('Method', ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY')),
|
||||||
'<comment>Defaults</comment> '.$this->formatRouterConfig($route->getDefaults()),
|
array('Requirements', ($requirements ? $this->formatRouterConfig($requirements) : 'NO CUSTOM')),
|
||||||
'<comment>Requirements</comment> '.($requirements ? $this->formatRouterConfig($requirements) : 'NO CUSTOM'),
|
array('Class', get_class($route)),
|
||||||
'<comment>Options</comment> '.$this->formatRouterConfig($route->getOptions()),
|
array('Defaults', $this->formatRouterConfig($route->getDefaults())),
|
||||||
|
array('Options', $this->formatRouterConfig($route->getOptions())),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($options['name'])) {
|
$table = new Table($this->getOutput());
|
||||||
array_unshift($description, '<comment>Name</comment> '.$options['name']);
|
$table->setHeaders($tableHeaders)->setRows($tableRows);
|
||||||
array_unshift($description, $this->formatSection('router', sprintf('Route "%s"', $options['name'])));
|
$table->render();
|
||||||
}
|
|
||||||
|
|
||||||
$this->writeText(implode("\n", $description)."\n", $options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -382,23 +387,24 @@ class TextDescriptor extends Descriptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $array
|
* @param array $config
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function formatRouterConfig(array $array)
|
private function formatRouterConfig(array $config)
|
||||||
{
|
{
|
||||||
if (!count($array)) {
|
if (empty($config)) {
|
||||||
return 'NONE';
|
return 'NONE';
|
||||||
}
|
}
|
||||||
|
|
||||||
$string = '';
|
ksort($config);
|
||||||
ksort($array);
|
|
||||||
foreach ($array as $name => $value) {
|
$configAsString = '';
|
||||||
$string .= ($string ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value);
|
foreach ($config as $key => $value) {
|
||||||
|
$configAsString .= sprintf("\n%s: %s", $key, $this->formatValue($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $string;
|
return trim($configAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user