Permalink
Browse files

[FrameworkBundle] adds routing/container descriptors

  • Loading branch information...
1 parent 77d3a85 commit 22f9bc887e3bf25f4a2ce16bbf0d45549bfd0178 @jfsimon jfsimon committed with fabpot Apr 30, 2013
Showing with 2,158 additions and 462 deletions.
  1. +29 −319 src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
  2. +16 −143 src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
  3. +273 −0 src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php
  4. +202 −0 src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
  5. +213 −0 src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php
  6. +308 −0 src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
  7. +341 −0 src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php
  8. +28 −0 src/Symfony/Bundle/FrameworkBundle/Console/Helper/DescriptorHelper.php
  9. +131 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php
  10. +27 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/JsonDescriptorTest.php
  11. +27 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/MarkdownDescriptorTest.php
  12. +95 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php
  13. +27 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/TextDescriptorTest.php
  14. +27 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/XmlDescriptorTest.php
  15. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_1.json
  16. +2 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_1.md
  17. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_1.txt
  18. +2 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_1.xml
  19. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_2.json
  20. +2 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_2.md
  21. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_2.txt
  22. +2 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_2.xml
  23. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json
  24. +27 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md
  25. +9 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.txt
  26. +7 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml
  27. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json
  28. +40 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md
  29. +10 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.txt
  30. +19 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml
  31. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json
  32. +18 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.md
  33. +7 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.txt
  34. +15 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.xml
  35. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json
  36. +22 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.md
  37. +6 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.txt
  38. +9 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.xml
  39. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json
  40. +4 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.md
  41. +7 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.txt
  42. +2 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.xml
  43. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json
  44. +11 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.md
  45. +10 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.txt
  46. +13 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.xml
  47. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameters_1.json
  48. +7 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameters_1.md
  49. +9 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameters_1.txt
  50. +7 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/parameters_1.xml
  51. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.json
  52. +9 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.md
  53. +12 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.txt
  54. +19 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_1.xml
  55. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.json
  56. +7 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.md
  57. +12 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.txt
  58. +13 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_2.xml
  59. +1 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.json
  60. +21 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.md
  61. +7 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.txt
  62. +33 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/route_collection_1.xml

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -11,6 +11,7 @@
namespace Symfony\Bundle\FrameworkBundle\Command;
+use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -50,7 +51,9 @@ protected function configure()
->setName('router:debug')
->setDefinition(array(
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('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'),
))
->setDescription('Displays current routes for an application')
->setHelp(<<<EOF
@@ -70,151 +73,21 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
+ $helper = new DescriptorHelper();
if ($name) {
- $this->outputRoute($output, $name);
- } else {
- $this->outputRoutes($output, null, $input->getOption('show-controllers'));
- }
- }
-
- protected function outputRoutes(OutputInterface $output, $routes = null, $showControllers = false)
- {
- if (null === $routes) {
- $routes = $this->getContainer()->get('router')->getRouteCollection()->all();
- }
-
- $output->writeln($this->getHelper('formatter')->formatSection('router', 'Current routes'));
-
- $maxName = strlen('name');
- $maxMethod = strlen('method');
- $maxScheme = strlen('scheme');
- $maxHost = strlen('host');
- $maxPath = strlen('path');
-
- foreach ($routes as $name => $route) {
- $method = $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY';
- $scheme = $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY';
- $host = '' !== $route->getHost() ? $route->getHost() : 'ANY';
- $path = $route->getPath();
- $maxName = max($maxName, strlen($name));
- $maxMethod = max($maxMethod, strlen($method));
- $maxScheme = max($maxScheme, strlen($scheme));
- $maxHost = max($maxHost, strlen($host));
- $maxPath = max($maxPath, strlen($path));
- }
-
- $format = '%-'.$maxName.'s %-'.$maxMethod.'s %-'.$maxScheme.'s %-'.$maxHost.'s %s';
- $formatHeader = '%-'.($maxName + 19).'s %-'.($maxMethod + 19).'s %-'.($maxScheme + 19).'s %-'.($maxHost + 19).'s %-'.($maxPath + 19).'s';
-
- if ($showControllers) {
- $format = str_replace('s %s', 's %-'.$maxPath.'s %s', $format);
- $formatHeader = $formatHeader . ' %s';
- }
-
- if ($showControllers) {
- $output->writeln(sprintf($formatHeader, '<comment>Name</comment>', '<comment>Method</comment>', '<comment>Scheme</comment>', '<comment>Host</comment>', '<comment>Path</comment>', '<comment>Controller</comment>'));
- } else {
- $output->writeln(sprintf($formatHeader, '<comment>Name</comment>', '<comment>Method</comment>', '<comment>Scheme</comment>', '<comment>Host</comment>', '<comment>Path</comment>'));
- }
-
- foreach ($routes as $name => $route) {
- $method = $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY';
- $scheme = $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY';
- $host = '' !== $route->getHost() ? $route->getHost() : 'ANY';
- if ($showControllers) {
- $defaultData = $route->getDefaults();
- $controller = $defaultData['_controller'] ? $defaultData['_controller'] : '';
- if ($controller instanceof \Closure) {
- $controller = 'Closure';
- } else {
- if (is_object($controller)) {
- $controller = get_class($controller);
- }
- }
- $output->writeln(sprintf($format, $name, $method, $scheme, $host, $route->getPath(), $controller), OutputInterface::OUTPUT_RAW);
- } else {
- $output->writeln(sprintf($format, $name, $method, $scheme, $host, $route->getPath()), OutputInterface::OUTPUT_RAW);
+ $route = $this->getContainer()->get('router')->getRouteCollection()->get($name);
+ if (!$route) {
+ throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
}
+ $helper->describe($output, $route, $input->getOption('format'), $input->getOption('raw'), array('name' => $name));
+ } else {
+ $routes = $this->getContainer()->get('router')->getRouteCollection();
+ $helper->describe($output, $routes, array(
+ 'format' => $input->getOption('format'),
+ 'raw_text' => $input->getOption('raw'),
+ 'show_controllers' => $input->getOption('show-controllers'),
+ ));
}
}
-
- /**
- * @throws \InvalidArgumentException When route does not exist
- */
- protected function outputRoute(OutputInterface $output, $name)
- {
- $route = $this->getContainer()->get('router')->getRouteCollection()->get($name);
- if (!$route) {
- throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
- }
-
- $output->writeln($this->getHelper('formatter')->formatSection('router', sprintf('Route "%s"', $name)));
-
- $method = $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY';
- $scheme = $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY';
- $host = '' !== $route->getHost() ? $route->getHost() : 'ANY';
-
- $output->write('<comment>Name</comment> ');
- $output->writeln($name, OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Path</comment> ');
- $output->writeln($route->getPath(), OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Host</comment> ');
- $output->writeln($host, OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Scheme</comment> ');
- $output->writeln($scheme, OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Method</comment> ');
- $output->writeln($method, OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Class</comment> ');
- $output->writeln(get_class($route), OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Defaults</comment> ');
- $output->writeln($this->formatConfigs($route->getDefaults()), OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Requirements</comment> ');
- // we do not want to show the schemes and methods again that are also in the requirements for BC
- $requirements = $route->getRequirements();
- unset($requirements['_scheme'], $requirements['_method']);
- $output->writeln($this->formatConfigs($requirements) ?: 'NO CUSTOM', OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Options</comment> ');
- $output->writeln($this->formatConfigs($route->getOptions()), OutputInterface::OUTPUT_RAW);
-
- $output->write('<comment>Path-Regex</comment> ');
- $output->writeln($route->compile()->getRegex(), OutputInterface::OUTPUT_RAW);
-
- if (null !== $route->compile()->getHostRegex()) {
- $output->write('<comment>Host-Regex</comment> ');
- $output->writeln($route->compile()->getHostRegex(), OutputInterface::OUTPUT_RAW);
- }
- }
-
- protected function formatValue($value)
- {
- if (is_object($value)) {
- return sprintf('object(%s)', get_class($value));
- }
-
- if (is_string($value)) {
- return $value;
- }
-
- return preg_replace("/\n\s*/s", '', var_export($value, true));
- }
-
- private function formatConfigs(array $array)
- {
- $string = '';
- ksort($array);
- foreach ($array as $name => $value) {
- $string .= ($string ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value);
- }
-
- return $string;
- }
}
Oops, something went wrong.

0 comments on commit 22f9bc8

Please sign in to comment.