-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add posibility to specify method in router:match #9340
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 all commits
d9bfc62
a19d824
97324a3
0f6320e
a6b927b
49cfc40
7329101
bc9edc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
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\Routing\RouterInterface; | ||
|
@@ -50,12 +51,14 @@ protected function configure() | |
->setName('router:match') | ||
->setDefinition(array( | ||
new InputArgument('path_info', InputArgument::REQUIRED, 'A path info'), | ||
new InputOption('method', 'm', InputOption::VALUE_OPTIONAL, 'Forces to match against the specified method'), | ||
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 would remove the 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.
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.
Also it would be nice to add one more option: scheme (defaults to 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 think the default should be all methods, not only GET? 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. The default cannot be all method. The request context has only 1 method. |
||
new InputOption('host', null, InputOption::VALUE_OPTIONAL, 'Forces the host to be the one specified by this parameter'), | ||
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.
|
||
)) | ||
->setDescription('Helps debug routes by simulating a path info match') | ||
->setHelp(<<<EOF | ||
The <info>%command.name%</info> simulates a path info match: | ||
|
||
<info>php %command.full_name% /foo</info> | ||
<info>php %command.full_name% /foo -m METHOD --host HOST</info> | ||
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.
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 would keep the old example and add a new one with real values instead of |
||
EOF | ||
) | ||
; | ||
|
@@ -67,7 +70,15 @@ protected function configure() | |
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$router = $this->getContainer()->get('router'); | ||
$matcher = new TraceableUrlMatcher($router->getRouteCollection(), $router->getContext()); | ||
$context = $router->getContext(); | ||
if ($method = $input->getOption('method')) { | ||
$context->setMethod($method); | ||
} | ||
if ($host = $input->getOption('host')) { | ||
$context->setHost($host); | ||
} | ||
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. After applying the changes asked by @Tobion, you can safely remove the conditions and always set the values (as it would set the default value if the options are not passed explicitly). 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 disagree here. The default values of the request context can be changed by changing the parameter. It would be weird if the command starts ignoring these overwritten defaults by always setting its own value 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.
What parameter are you referring to? 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. If you mean a custom subclass with changed parameter defaults, then IMHO we should still set the values in the command to make it independent and work consistently. Otherwise the command would behave differently depending on what request context is used. |
||
|
||
$matcher = new TraceableUrlMatcher($router->getRouteCollection(), $context); | ||
|
||
$traces = $matcher->getTraces($input->getArgument('path_info')); | ||
|
||
|
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.
should be reverted
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.
what do you mean by reverted? That it should not be marked as modified in the diff?
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.
you removed the ending comma