Skip to content

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

Closed
wants to merge 8 commits into from

Conversation

pmartelletti
Copy link
Contributor

I think this was not possible, or I just was not able to find it anywhere, so I just implemented myself. Please feel free to ignore this PR if this was already possible from the command line, but please DO tell me how is it done. Thanks!

I think this was not possible, or I just was not able to find it anywhere, so I just implemented myself.
@@ -50,12 +50,13 @@ protected function configure()
->setName('router:match')
->setDefinition(array(
new InputArgument('path_info', InputArgument::REQUIRED, 'A path info'),
new InputArgument('_method', InputArgument::OPTIONAL, 'Forces to match against the specified method (optional)')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without underscore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@pmartelletti
Copy link
Contributor Author

Should I do a new PR with the suggested changes?

$matcher = new TraceableUrlMatcher($router->getRouteCollection(), $router->getContext());
$context = $router->getContext();
$method = $input->getArgument('method');
if ( $method ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without spaces insde ()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please have a look at the symfony cs

@Tobion
Copy link
Contributor

Tobion commented Oct 18, 2013

@pmartelletti I like the PR. I also had this idea. You don't need a new PR. Updating this one is fine.

@stof
Copy link
Member

stof commented Oct 18, 2013

we would need host as well, as the routes can be aware of the host now

@pmartelletti
Copy link
Contributor Author

Do you want me to add 'host' as an optiona paramter too?

@pmartelletti
Copy link
Contributor Author

What do you think about it now? 😟

@@ -49,13 +50,25 @@ protected function configure()
$this
->setName('router:match')
->setDefinition(array(
new InputArgument('path_info', InputArgument::REQUIRED, 'A path info'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be reverted

Copy link
Contributor Author

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?

Copy link
Member

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

))
->addOption('method', 'm', InputOption::VALUE_OPTIONAL, 'Forces to match against the specified method')
->addOption('host', null, InputOption::VALUE_OPTIONAL, 'Forces the host to be the one specified by this parameter')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those 2 lines should be moved to the setDefinition call like done in other Symfony commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the AssetsInstallCommand options are set like this, that's why I opted to make it this way. 😟 Sorry about that.

@@ -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'),
new InputOption('host', null, InputOption::VALUE_OPTIONAL, 'Forces the host to be the one specified by this parameter')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comma at the end of this one too?

@@ -67,7 +70,17 @@ 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();
$method = $input->getOption('method');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could inject elegantly the assignments into the if expressions

if ($method = $input->getOption('method')) {

a la @fabpot

@cordoval
Copy link
Contributor

also add some command testing

@hacfi
Copy link
Contributor

hacfi commented Oct 28, 2013

Great addition..three days ago I was disappointed to find out that it wasn’t implemented yet!

@pmartelletti
Copy link
Contributor Author

@cordoval the actual command does not have any testing, or at least it's not under

FrameworkBundle/Tests/Command/

where I expected it should be. If tests are somewhere else, would be appreciated if you point me where so I don't duplicate testing. 😄

@wouterj
Copy link
Member

wouterj commented Nov 6, 2013

You're correct, there are no tests for this command. Could you please create them?

@@ -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'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the m shortcut here and use null instead like you did for the host.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forces to match against the specified method -> Sets the HTTP method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALUE_OPTIONAL should also be changed. It's not optional because just specifying --method doesn't make sense.
So instead it should be required and specify a default (GET) for it (fifth argument AFAIK).
The same also applies for host (localhost). These are the defaults of https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/RequestContext.php#L53 as well.

Also it would be nice to add one more option: scheme (defaults to http).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default should be all methods, not only GET?

Copy link
Member

Choose a reason for hiding this comment

The 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.

@fabpot
Copy link
Member

fabpot commented Dec 29, 2013

Can you add the PR header in your description? (see http://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request)?

}
if ($host = $input->getOption('host')) {
$context->setHost($host);
}
Copy link
Member

Choose a reason for hiding this comment

The 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).

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by changing the parameter

What parameter are you referring to?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@jakzal
Copy link
Contributor

jakzal commented Jan 8, 2014

@pmartelletti do you have time to finish this one off? There's little left to do (remember to add the PR table).

@pmartelletti
Copy link
Contributor Author

Yes i will , as soon as i'm back from holidays later next week. Sorry about
the delay!

El miércoles, 8 de enero de 2014, Jakub Zalas escribió:

@pmartelletti https://github.com/pmartelletti do you have time to
finish this one off? There's little left to do (remember to add the PR
tablehttp://fabbot.io/report/symfony/symfony/9340/bc9edc2bda5671e1df2901fb29a60076a48c862c
).


Reply to this email directly or view it on GitHubhttps://github.com//pull/9340#issuecomment-31877145
.

Pablo María Martelletti

@franmomu
Copy link
Contributor

franmomu commented Mar 5, 2014

Should a scheme option be added as well?

EDIT: Sorry, I have just realised that this was said before.

@pmartelletti
Copy link
Contributor Author

I've totally forgot about this PR. I have to make some updates on it and update existing one.

@romainneutron
Copy link
Contributor

This can be closed in favor of #10439

@fabpot fabpot closed this Mar 13, 2014
fabpot added a commit that referenced this pull request Mar 13, 2014
… host in router:match command (romainneutron)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[FrameworkBundle] Add posibility to specify method and host in router:match command

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

Replaces #9340

Commits
-------

acc66b9 [FrameworkBundle] Add posibility to specify method and host in router:match command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants