Skip to content

[Routing] Fix: annotation loader ignores method's default values #30825

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

Merged
merged 1 commit into from
Apr 3, 2019
Merged

[Routing] Fix: annotation loader ignores method's default values #30825

merged 1 commit into from
Apr 3, 2019

Conversation

voronkovich
Copy link
Contributor

Q A
Branch? 4.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets no
License MIT
Doc PR no

In some cases annotation loader ignores method param's default values.
For example this code won't work as expected:

/**
 * @Route("/hello/{name<\w++>}", methods="GET", name="hello")
 */
public function hello(Request $request, string $name = 'World'): Response
{
    // If you try to open "/hello" path an exception (No route found for "GET /hello") will be thrown.
    return $this->json([
        'hello' => \sprintf('Hello, %s!', $name),
    ]);
}

@nicolas-grekas
Copy link
Member

Note that 4.1 is EOLed, this is for 4.2.

@nicolas-grekas nicolas-grekas changed the base branch from 4.1 to 4.2 April 3, 2019 13:26
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(I rebased and addresses my review)

@voronkovich
Copy link
Contributor Author

@nicolas-grekas, thank you for the help!

@fabpot
Copy link
Member

fabpot commented Apr 3, 2019

Thank you @voronkovich.

@fabpot fabpot merged commit 9b37793 into symfony:4.2 Apr 3, 2019
fabpot added a commit that referenced this pull request Apr 3, 2019
…values (voronkovich)

This PR was merged into the 4.2 branch.

Discussion
----------

[Routing] Fix: annotation loader ignores method's default values

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? |no
| Tests pass?   | yes
| Fixed tickets | no
| License       | MIT
| Doc PR        | no

In some cases annotation loader ignores method param's default values.
For example this code won't work as expected:
```php
/**
 * @route("/hello/{name<\w++>}", methods="GET", name="hello")
 */
public function hello(Request $request, string $name = 'World'): Response
{
    // If you try to open "/hello" path an exception (No route found for "GET /hello") will be thrown.
    return $this->json([
        'hello' => \sprintf('Hello, %s!', $name),
    ]);
}
```

Commits
-------

9b37793 [Routing] Fix: annotation loader ignores method's default values
@fabpot fabpot mentioned this pull request Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants