merged branch Tobion/debug-command (PR #7301)

This PR was merged into the 2.2 branch.

Commits
-------

15bf033 [FrameworkBundle] fix router debug command
d16d193 [FramworkBundle] removed unused property of trans update command
5361f83 [FramworkBundle] fix phpdoc of commands

Discussion
----------

[FrameworkBundle] router debug command fix

| Q             | A
| ------------- | ---
| Bug fix?      | [yes]
| New feature?  | [no]
| BC breaks?    | [no]
| Deprecations? | [no]
| Tests pass?   | [yes]
| License       | MIT

See commits.
This commit is contained in:
Fabien Potencier 2013-03-08 14:32:59 +01:00
commit 62f3d2acd5
12 changed files with 95 additions and 82 deletions

View File

@ -15,7 +15,6 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Finder\Finder;
/**
@ -26,7 +25,7 @@ use Symfony\Component\Finder\Finder;
class AssetsInstallCommand extends ContainerAwareCommand
{
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -62,9 +61,9 @@ EOT
}
/**
* @see Command
* {@inheritdoc}
*
* @throws \InvalidArgumentException When the target directory does not exist
* @throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@ -28,7 +28,7 @@ class CacheClearCommand extends ContainerAwareCommand
protected $name;
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{

View File

@ -23,7 +23,7 @@ use Symfony\Component\Console\Output\OutputInterface;
class CacheWarmupCommand extends ContainerAwareCommand
{
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{

View File

@ -25,7 +25,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
class ConfigDumpReferenceCommand extends ContainerDebugCommand
{
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -53,7 +53,9 @@ EOF
}
/**
* @see Command
* {@inheritdoc}
*
* @throws \LogicException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@ -23,7 +23,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
abstract class ContainerAwareCommand extends Command implements ContainerAwareInterface
{
/**
* @var ContainerInterface
* @var ContainerInterface|null
*/
private $container;
@ -40,7 +40,7 @@ abstract class ContainerAwareCommand extends Command implements ContainerAwareIn
}
/**
* @see ContainerAwareInterface::setContainer()
* {@inheritdoc}
*/
public function setContainer(ContainerInterface $container = null)
{

View File

@ -29,12 +29,12 @@ use Symfony\Component\Config\FileLocator;
class ContainerDebugCommand extends ContainerAwareCommand
{
/**
* @var ContainerBuilder
* @var ContainerBuilder|null
*/
protected $containerBuilder;
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -74,7 +74,9 @@ EOF
}
/**
* @see Command
* {@inheritdoc}
*
* @throws \LogicException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@ -307,7 +309,7 @@ EOF
*
* @param string $serviceId The service id to resolve
*
* @return \Symfony\Component\DependencyInjection\Definition|\Symfony\Component\DependencyInjection\Alias
* @return Definition|Alias
*/
protected function resolveServiceDefinition($serviceId)
{
@ -328,7 +330,7 @@ EOF
* Renders list of tagged services grouped by tag
*
* @param OutputInterface $output
* @param bool $showPrivate
* @param Boolean $showPrivate
*/
protected function outputTags(OutputInterface $output, $showPrivate = false)
{

View File

@ -26,7 +26,7 @@ use Symfony\Component\Routing\RouterInterface;
class RouterApacheDumperCommand extends ContainerAwareCommand
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function isEnabled()
{
@ -42,7 +42,7 @@ class RouterApacheDumperCommand extends ContainerAwareCommand
}
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -65,7 +65,7 @@ EOF
}
/**
* @see Command
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@ -20,11 +20,12 @@ use Symfony\Component\Routing\RouterInterface;
* A console command for retrieving information about routes
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Tobias Schultze <http://tobion.de>
*/
class RouterDebugCommand extends ContainerAwareCommand
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function isEnabled()
{
@ -40,7 +41,7 @@ class RouterDebugCommand extends ContainerAwareCommand
}
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -60,7 +61,9 @@ EOF
}
/**
* @see Command
* {@inheritdoc}
*
* @throws \InvalidArgumentException When route does not exist
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@ -83,34 +86,28 @@ EOF
$maxName = strlen('name');
$maxMethod = strlen('method');
$maxScheme = strlen('scheme');
$maxHost = strlen('host');
foreach ($routes as $name => $route) {
$requirements = $route->getRequirements();
$method = isset($requirements['_method'])
? strtoupper(is_array($requirements['_method'])
? implode(', ', $requirements['_method']) : $requirements['_method']
)
: 'ANY';
$method = $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY';
$scheme = $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY';
$host = '' !== $route->getHost() ? $route->getHost() : 'ANY';
$maxName = max($maxName, strlen($name));
$maxMethod = max($maxMethod, strlen($method));
$maxScheme = max($maxScheme, strlen($scheme));
$maxHost = max($maxHost, strlen($host));
}
$format = '%-'.$maxName.'s %-'.$maxMethod.'s %-'.$maxHost.'s %s';
// displays the generated routes
$format1 = '%-'.($maxName + 19).'s %-'.($maxMethod + 19).'s %-'.($maxHost + 19).'s %s';
$output->writeln(sprintf($format1, '<comment>Name</comment>', '<comment>Method</comment>', '<comment>Host</comment>', '<comment>Pattern</comment>'));
$format = '%-'.$maxName.'s %-'.$maxMethod.'s %-'.$maxScheme.'s %-'.$maxHost.'s %s';
$formatHeader = '%-'.($maxName + 19).'s %-'.($maxMethod + 19).'s %-'.($maxScheme + 19).'s %-'.($maxHost + 19).'s %s';
$output->writeln(sprintf($formatHeader, '<comment>Name</comment>', '<comment>Method</comment>', '<comment>Scheme</comment>', '<comment>Host</comment>', '<comment>Path</comment>'));
foreach ($routes as $name => $route) {
$requirements = $route->getRequirements();
$method = isset($requirements['_method'])
? strtoupper(is_array($requirements['_method'])
? implode(', ', $requirements['_method']) : $requirements['_method']
)
: 'ANY';
$method = $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY';
$scheme = $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY';
$host = '' !== $route->getHost() ? $route->getHost() : 'ANY';
$output->writeln(sprintf($format, $name, $method, $host, $route->getPath()));
$output->writeln(sprintf($format, $name, $method, $scheme, $host, $route->getPath()), OutputInterface::OUTPUT_RAW);
}
}
@ -124,41 +121,49 @@ EOF
throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
}
$host = '' !== $route->getHost() ? $route->getHost() : 'ANY';
$output->writeln($this->getHelper('formatter')->formatSection('router', sprintf('Route "%s"', $name)));
$output->writeln(sprintf('<comment>Name</comment> %s', $name));
$output->writeln(sprintf('<comment>Pattern</comment> %s', $route->getPath()));
$output->writeln(sprintf('<comment>Host</comment> %s', $host));
$output->writeln(sprintf('<comment>Class</comment> %s', get_class($route)));
$method = $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY';
$scheme = $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY';
$host = '' !== $route->getHost() ? $route->getHost() : 'ANY';
$defaults = '';
$d = $route->getDefaults();
ksort($d);
foreach ($d as $name => $value) {
$defaults .= ($defaults ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value);
}
$output->writeln(sprintf('<comment>Defaults</comment> %s', $defaults));
$output->write('<comment>Name</comment> ');
$output->writeln($name, OutputInterface::OUTPUT_RAW);
$requirements = '';
$r = $route->getRequirements();
ksort($r);
foreach ($r as $name => $value) {
$requirements .= ($requirements ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value);
}
$requirements = '' !== $requirements ? $requirements : 'NONE';
$output->writeln(sprintf('<comment>Requirements</comment> %s', $requirements));
$output->write('<comment>Path</comment> ');
$output->writeln($route->getPath(), OutputInterface::OUTPUT_RAW);
$options = '';
$o = $route->getOptions();
ksort($o);
foreach ($o as $name => $value) {
$options .= ($options ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value);
$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);
}
$output->writeln(sprintf('<comment>Options</comment> %s', $options));
$output->write('<comment>Regex</comment> ');
$output->writeln(preg_replace('/^ /', '', preg_replace('/^/m', ' ', $route->compile()->getRegex())), OutputInterface::OUTPUT_RAW);
}
protected function formatValue($value)
@ -173,4 +178,15 @@ EOF
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;
}
}

View File

@ -25,7 +25,7 @@ use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
class RouterMatchCommand extends ContainerAwareCommand
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function isEnabled()
{
@ -41,7 +41,7 @@ class RouterMatchCommand extends ContainerAwareCommand
}
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -61,7 +61,7 @@ EOF
}
/**
* @see Command
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@ -25,7 +25,7 @@ use Symfony\Component\Process\ProcessBuilder;
class ServerRunCommand extends ContainerAwareCommand
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function isEnabled()
{
@ -37,7 +37,7 @@ class ServerRunCommand extends ContainerAwareCommand
}
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -74,7 +74,7 @@ EOF
}
/**
* @see Command
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@ -27,13 +27,7 @@ use Symfony\Component\Yaml\Yaml;
class TranslationUpdateCommand extends ContainerAwareCommand
{
/**
* Compiled catalogue of messages.
* @var MessageCatalogue
*/
protected $catalogue;
/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function configure()
{
@ -74,7 +68,7 @@ EOF
}
/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@ -23,7 +23,7 @@ interface ContainerAwareInterface
/**
* Sets the Container.
*
* @param ContainerInterface $container A ContainerInterface instance
* @param ContainerInterface|null $container A ContainerInterface instance or null
*
* @api
*/