-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Applied the new styles to the router: commands #14132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f5f0488
9ebdcc1
488a80f
f72b69b
e203706
f9de063
90a3e18
83cce3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,12 @@ | |
|
||
namespace Symfony\Bundle\FrameworkBundle\Command; | ||
|
||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
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\Matcher\TraceableUrlMatcher; | ||
|
||
|
@@ -60,7 +61,7 @@ protected function configure() | |
The <info>%command.name%</info> shows which routes match a given request and which don't and for what reason: | ||
|
||
<info>php %command.full_name% /foo</info> | ||
|
||
or | ||
|
||
<info>php %command.full_name% /foo --method POST --scheme https --host symfony.com --verbose</info> | ||
|
@@ -75,6 +76,8 @@ protected function configure() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$output = new SymfonyStyle($input, $output); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we use a different variable name ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we need another name, since we're replacing the output we're using by a wrapped one, which implements the exact same interface (and an additional one, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overriding a method argument imho is no good style (see also #14595 (comment) for the same). |
||
|
||
$router = $this->getContainer()->get('router'); | ||
$context = $router->getContext(); | ||
if (null !== $method = $input->getOption('method')) { | ||
|
@@ -91,25 +94,26 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
$traces = $matcher->getTraces($input->getArgument('path_info')); | ||
|
||
$output->newLine(); | ||
|
||
$matches = false; | ||
foreach ($traces as $trace) { | ||
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']) { | ||
$output->writeln(sprintf('<fg=green>Route "%s" matches</>', $trace['name'])); | ||
$output->success(sprintf('Route "%s" matches', $trace['name'])); | ||
|
||
$routerDebugcommand = $this->getApplication()->find('debug:router'); | ||
$output->writeln(''); | ||
$routerDebugcommand->run(new ArrayInput(array('name' => $trace['name'])), $output); | ||
$routerDebugCommand = $this->getApplication()->find('debug:router'); | ||
$routerDebugCommand->run(new ArrayInput(array('name' => $trace['name'])), $output); | ||
|
||
$matches = true; | ||
} 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) { | ||
$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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no
->table()
method in the OutputInterface. so the typehint looks weird