bug #9195 [WIP] [FrameworkBundle] fixed container:debug and router:debug commands (fabpot)
This PR was merged into the master branch. Discussion ---------- [WIP] [FrameworkBundle] fixed container:debug and router:debug commands | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a #7887 is buggy as hell :( Commits -------fe5961a
[FrameworkBundle] moved router:debug and container:debug to use the compact layoutbd16157
[FrameworkBundle] changed JSON descriptors to be more readable on PHP 5.4+1d210f8
[FrameworkBundle] changed the router:debug to use the shortcut notation for the controllerd997dfa
[FrameworkBundle] fixed container:debug and router:debug commands
This commit is contained in:
commit
4b094e2b12
@ -46,7 +46,7 @@ class ContainerDebugCommand extends ContainerAwareCommand
|
|||||||
new InputOption('tags', null, InputOption::VALUE_NONE, 'Displays tagged services for an application'),
|
new InputOption('tags', null, InputOption::VALUE_NONE, 'Displays tagged services for an application'),
|
||||||
new InputOption('parameter', null, InputOption::VALUE_REQUIRED, 'Displays a specific parameter for an application'),
|
new InputOption('parameter', null, InputOption::VALUE_REQUIRED, 'Displays a specific parameter for an application'),
|
||||||
new InputOption('parameters', null, InputOption::VALUE_NONE, 'Displays parameters for an application'),
|
new InputOption('parameters', null, InputOption::VALUE_NONE, 'Displays parameters for an application'),
|
||||||
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output description in other formats'),
|
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output description in other formats', 'txt'),
|
||||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
|
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
|
||||||
))
|
))
|
||||||
->setDescription('Displays current services for an application')
|
->setDescription('Displays current services for an application')
|
||||||
@ -114,7 +114,9 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
$helper = new DescriptorHelper();
|
$helper = new DescriptorHelper();
|
||||||
$helper->describe($output, $object, $input->getOption('format'), $input->getOption('raw'), $options);
|
$options['format'] = $input->getOption('format');
|
||||||
|
$options['raw_text'] = $input->getOption('raw');
|
||||||
|
$helper->describe($output, $object, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,6 +17,7 @@ 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\Routing\RouterInterface;
|
use Symfony\Component\Routing\RouterInterface;
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A console command for retrieving information about routes
|
* A console command for retrieving information about routes
|
||||||
@ -52,7 +53,7 @@ class RouterDebugCommand extends ContainerAwareCommand
|
|||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'),
|
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'),
|
||||||
new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'),
|
new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'),
|
||||||
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output route(s) in other formats'),
|
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output route(s) in other formats', 'txt'),
|
||||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'),
|
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'),
|
||||||
))
|
))
|
||||||
->setDescription('Displays current routes for an application')
|
->setDescription('Displays current routes for an application')
|
||||||
@ -80,9 +81,19 @@ 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));
|
||||||
}
|
}
|
||||||
$helper->describe($output, $route, $input->getOption('format'), $input->getOption('raw'), array('name' => $name));
|
$this->convertController($route);
|
||||||
|
$helper->describe($output, $route, array(
|
||||||
|
'format' => $input->getOption('format'),
|
||||||
|
'raw_text' => $input->getOption('raw'),
|
||||||
|
'name' => $name,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
$routes = $this->getContainer()->get('router')->getRouteCollection();
|
$routes = $this->getContainer()->get('router')->getRouteCollection();
|
||||||
|
|
||||||
|
foreach ($routes as $route) {
|
||||||
|
$this->convertController($route);
|
||||||
|
}
|
||||||
|
|
||||||
$helper->describe($output, $routes, array(
|
$helper->describe($output, $routes, array(
|
||||||
'format' => $input->getOption('format'),
|
'format' => $input->getOption('format'),
|
||||||
'raw_text' => $input->getOption('raw'),
|
'raw_text' => $input->getOption('raw'),
|
||||||
@ -90,4 +101,15 @@ EOF
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function convertController(Route $route)
|
||||||
|
{
|
||||||
|
$nameParser = $this->getContainer()->get('controller_name_converter');
|
||||||
|
if ($route->hasDefault('_controller')) {
|
||||||
|
try {
|
||||||
|
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
|
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
|
||||||
|
|
||||||
|
if (!defined('JSON_PRETTY_PRINT')) {
|
||||||
|
define('JSON_PRETTY_PRINT', 128);
|
||||||
|
}
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Alias;
|
use Symfony\Component\DependencyInjection\Alias;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
@ -131,7 +135,7 @@ class JsonDescriptor extends Descriptor
|
|||||||
*/
|
*/
|
||||||
private function writeData(array $data, array $options)
|
private function writeData(array $data, array $options)
|
||||||
{
|
{
|
||||||
$this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
|
$this->write(json_encode($data, (isset($options['json_encoding']) ? $options['json_encoding'] : 0) | JSON_PRETTY_PRINT)."\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +28,7 @@ class MarkdownDescriptor extends Descriptor
|
|||||||
}
|
}
|
||||||
$this->describeRoute($route, array('name' => $name));
|
$this->describeRoute($route, array('name' => $name));
|
||||||
}
|
}
|
||||||
|
$this->write("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,8 +50,9 @@ class MarkdownDescriptor extends Descriptor
|
|||||||
."\n".'- Path-Regex: '.$route->compile()->getRegex();
|
."\n".'- Path-Regex: '.$route->compile()->getRegex();
|
||||||
|
|
||||||
$this->write(isset($options['name'])
|
$this->write(isset($options['name'])
|
||||||
? $options['name']."\n".str_repeat('-', strlen($options['name']))."\n".$output
|
? $options['name']."\n".str_repeat('-', strlen($options['name']))."\n\n".$output
|
||||||
: $output);
|
: $output);
|
||||||
|
$this->write("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,17 +135,17 @@ class MarkdownDescriptor extends Descriptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($services['definitions'])) {
|
if (!empty($services['definitions'])) {
|
||||||
$this->write("\n\nDefinitions\n-----------");
|
$this->write("\n\nDefinitions\n-----------\n");
|
||||||
foreach ($services['definitions'] as $id => $service) {
|
foreach ($services['definitions'] as $id => $service) {
|
||||||
$this->write("\n\n");
|
$this->write("\n");
|
||||||
$this->describeContainerDefinition($service, array('id' => $id));
|
$this->describeContainerDefinition($service, array('id' => $id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($services['aliases'])) {
|
if (!empty($services['aliases'])) {
|
||||||
$this->write("\n\nAliases\n-------");
|
$this->write("\n\nAliases\n-------\n");
|
||||||
foreach ($services['aliases'] as $id => $service) {
|
foreach ($services['aliases'] as $id => $service) {
|
||||||
$this->write("\n\n");
|
$this->write("\n");
|
||||||
$this->describeContainerAlias($service, array('id' => $id));
|
$this->describeContainerAlias($service, array('id' => $id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,7 +184,7 @@ class MarkdownDescriptor extends Descriptor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->write(isset($options['id']) ? sprintf("**`%s`:**\n%s", $options['id'], $output) : $output);
|
$this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -193,7 +195,7 @@ class MarkdownDescriptor extends Descriptor
|
|||||||
$output = '- Service: `'.$alias.'`'
|
$output = '- Service: `'.$alias.'`'
|
||||||
."\n".'- Public: '.($alias->isPublic() ? 'yes' : 'no');
|
."\n".'- Public: '.($alias->isPublic() ? 'yes' : 'no');
|
||||||
|
|
||||||
$this->write(isset($options['id']) ? sprintf("**`%s`:**\n%s", $options['id'], $output) : $output);
|
$this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formatRouterConfig(array $array)
|
private function formatRouterConfig(array $array)
|
||||||
|
@ -23,6 +23,7 @@ class TextDescriptor extends Descriptor
|
|||||||
$showControllers = isset($options['show_controllers']) && $options['show_controllers'];
|
$showControllers = isset($options['show_controllers']) && $options['show_controllers'];
|
||||||
$headers = array('Name', 'Method', 'Scheme', 'Host', 'Path');
|
$headers = array('Name', 'Method', 'Scheme', 'Host', 'Path');
|
||||||
$table = new TableHelper();
|
$table = new TableHelper();
|
||||||
|
$table->setLayout(TableHelper::LAYOUT_COMPACT);
|
||||||
$table->setHeaders($showControllers ? array_merge($headers, array('Controller')) : $headers);
|
$table->setHeaders($showControllers ? array_merge($headers, array('Controller')) : $headers);
|
||||||
|
|
||||||
foreach ($routes->all() as $name => $route) {
|
foreach ($routes->all() as $name => $route) {
|
||||||
@ -35,14 +36,11 @@ class TextDescriptor extends Descriptor
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($showControllers) {
|
if ($showControllers) {
|
||||||
$defaultData = $route->getDefaults();
|
$controller = $route->getDefault('_controller');
|
||||||
$controller = $defaultData['_controller'] ? $defaultData['_controller'] : '';
|
|
||||||
if ($controller instanceof \Closure) {
|
if ($controller instanceof \Closure) {
|
||||||
$controller = 'Closure';
|
$controller = 'Closure';
|
||||||
} else {
|
} elseif (is_object($controller)) {
|
||||||
if (is_object($controller)) {
|
$controller = get_class($controller);
|
||||||
$controller = get_class($controller);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$row[] = $controller;
|
$row[] = $controller;
|
||||||
}
|
}
|
||||||
@ -84,7 +82,7 @@ class TextDescriptor extends Descriptor
|
|||||||
$description[] = '<comment>Host-Regex</comment> '.$route->compile()->getHostRegex();
|
$description[] = '<comment>Host-Regex</comment> '.$route->compile()->getHostRegex();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writeText(implode("\n", $description), $options);
|
$this->writeText(implode("\n", $description)."\n", $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,6 +91,7 @@ class TextDescriptor extends Descriptor
|
|||||||
protected function describeContainerParameters(ParameterBag $parameters, array $options = array())
|
protected function describeContainerParameters(ParameterBag $parameters, array $options = array())
|
||||||
{
|
{
|
||||||
$table = new TableHelper();
|
$table = new TableHelper();
|
||||||
|
$table->setLayout(TableHelper::LAYOUT_COMPACT);
|
||||||
$table->setHeaders(array('Parameter', 'Value'));
|
$table->setHeaders(array('Parameter', 'Value'));
|
||||||
|
|
||||||
foreach ($this->sortParameters($parameters) as $parameter => $value) {
|
foreach ($this->sortParameters($parameters) as $parameter => $value) {
|
||||||
@ -193,6 +192,7 @@ class TextDescriptor extends Descriptor
|
|||||||
$tagsNames = array_keys($maxTags);
|
$tagsNames = array_keys($maxTags);
|
||||||
|
|
||||||
$table = new TableHelper();
|
$table = new TableHelper();
|
||||||
|
$table->setLayout(TableHelper::LAYOUT_COMPACT);
|
||||||
$table->setHeaders(array_merge(array('Service ID'), $tagsNames, array('Scope', 'Class name')));
|
$table->setHeaders(array_merge(array('Service ID'), $tagsNames, array('Scope', 'Class name')));
|
||||||
|
|
||||||
foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
|
foreach ($this->sortServiceIds($serviceIds) as $serviceId) {
|
||||||
@ -256,7 +256,7 @@ class TextDescriptor extends Descriptor
|
|||||||
$description[] = sprintf('<comment>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
|
$description[] = sprintf('<comment>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
|
||||||
$description[] = sprintf('<comment>Required File</comment> %s', $definition->getFile() ? $definition->getFile() : '-');
|
$description[] = sprintf('<comment>Required File</comment> %s', $definition->getFile() ? $definition->getFile() : '-');
|
||||||
|
|
||||||
$this->writeText(implode("\n", $description), $options);
|
$this->writeText(implode("\n", $description)."\n", $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user