-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.2][Routing] Added support for default attributes with default values of method params #5904
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
Conversation
I'm unsure. How does one know if that param defines a default value or a requirement? It's too vague. |
It's only a default value, not a requirement. |
Yes, but its not clear. It could also be a shortcut to |
it is the default php behavior. It's a default value for a variable... |
@Tobion using the default value of the method to set a requirement does not make any sense. I don't see why someone would expect this behavior |
@lyrixx Can you add some unit tests? |
Oh I misunderstood the PR. I thought this makes the |
@@ -149,6 +149,11 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl | |||
} | |||
|
|||
$defaults = array_merge($globals['defaults'], $annot->getDefaults()); | |||
foreach ($method->getParameters() as $param) { | |||
if ($param->isOptional()) { | |||
$defaults[$param->getName()] = $param->getdefaultvalue(); |
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.
getDefaultValue()
@lyrixx Can you finish this PR? |
@fabpot Yes i will as soon as possible. |
I rebase and amend my commit. (I changed doc in commit message to be less confusing) I will try to add tests. |
… method params You can configure default values likes this: ``` php /** * @route("/hi/{username}", name="hi") */ public function hiAction($username = "Bob") { return new Response($username); } ```
@fabpot I added new tests. I tried to made very atomic commits. |
This PR was merged into the master branch. Commits ------- 79d7839 [Doc] Added more doc about default value 06e22ab [Doc] Be more consistant on routing example Discussion ---------- Doc command default value see symfony/symfony#5904
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
With this patch, you can configure your default values likes this: