-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Fixed the interface description of the url generator interface #28321
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
Can we throw a deprecation when it returns null and adjust the signature to |
symfony/src/Symfony/Component/Routing/Generator/UrlGenerator.php Lines 159 to 167 in d2e9e0b
This is the only case, and AFAIK intended to not throw. Currently At least in practice i think this null is already casted to string in app code. symfony/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php Lines 53 to 69 in bc45a0e
|
I agree returning null does not make sense for this method. It could just be changed to an empty string when not strictRequirements |
I agree with @Tobion |
Would this be a bugfix then (target against 2.8 branch)? |
Merging as is in 2.8, changing |
Thank you @Toflar. |
…erator interface (Toflar) This PR was merged into the 2.8 branch. Discussion ---------- [Routing] Fixed the interface description of the url generator interface | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | The `UrlGenerator` has always been able to return `null`. Many tests assert this for many years but the interface actually always only allowed a `string` return. Examples for tests: - https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php#L206 - https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php#L217 - https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php#L471 So I think I would not consider this change as a BC break but rather a doc fix because it seems like `null` has always been an accepted return value. Commits ------- d2e9e0b Fixed the interface description of the url generator interface
This should not have been merged IMO. Now people will say it's a bc break to change the interface in master again when null wasn't even documented for years. |
Right, reverted. |
* 2.8: [appveyor] fix Revert "minor #28321 [Routing] Fixed the interface description of the url generator interface (Toflar)" remove cache warmers when Twig cache is disabled [HttpKernel][FrameworkBundle] Fix escaping of serialized payloads passed to test clients chore: rename Appveyor filename Fixed the interface description of the url generator interface Format file size in validation message according to binaryFormat option
* 3.4: [appveyor] fix Revert "minor #28321 [Routing] Fixed the interface description of the url generator interface (Toflar)" Fixed caching of templates in default path on cache warmup remove cache warmers when Twig cache is disabled [HttpKernel][FrameworkBundle] Fix escaping of serialized payloads passed to test clients chore: rename Appveyor filename Fixed the interface description of the url generator interface Format file size in validation message according to binaryFormat option
* 4.1: [appveyor] fix [DI] Fix dumping some complex service graphs Revert "minor #28321 [Routing] Fixed the interface description of the url generator interface (Toflar)" Fixed caching of templates in default path on cache warmup added missing LICENSE file remove cache warmers when Twig cache is disabled [Workflow] Make sure we do not run the next transition on an updated state change baseUrl to basePath to fix wrong profiler url [HttpKernel][FrameworkBundle] Fix escaping of serialized payloads passed to test clients chore: rename Appveyor filename Fixed the interface description of the url generator interface Format file size in validation message according to binaryFormat option
Description ----------- As outlined in symfony/symfony#28321 we cannot rely on the url generator of the router to always return a string. This was an issue in the interface docs of Symfony. Commits ------- 5aaf547 Fixed unhandled null case in contao framework ef39a73 Added unit test 10268b1 Rename the test method
Description ----------- As outlined in symfony/symfony#28321 we cannot rely on the url generator of the router to always return a string. This was an issue in the interface docs of Symfony. Commits ------- 5aaf5471 Fixed unhandled null case in contao framework ef39a735 Added unit test 10268b10 Rename the test method
FYI, this was implemented in #30390 |
…ce::generate to remove null (shieldo) This PR was merged into the 3.4 branch. Discussion ---------- [Routing] revert the return type for UrlGeneratorInterface::generate to remove null …to remove null | Q | A | ------------- | --- | Branch? | 3.4 (only) | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT Bit of a casualty of commit tennis this: A change to add `null` here as an option for how `UrlGeneratorInterface::generate()` (rather than the concrete `UrlGenerator`) was merged in #28321, but then [reverted](90494c2) for the reason [that this could be seen as a BC break](#28321 (comment)), as the `null` return had not previously been documented (and is still not as part of the interface method docs). However, in a subsequent change (#33252) with a wider scope, this doc change was added _back_ in order to reflect the underlying implementation as a result of a PHPStorm plugin complaining. There's no indication though of what a `null` return here though would mean, and for the same reason as the first revert (that this should be seen as a BC break), I'd like to submit this to be reverted for the 3.4 branch. (In 4.4 the `null` has already been removed.) Having the interface indicating that this method can return `null` necessitates introducing a lot of actually redundant null checks in code that is covered by static analysis tools such as PHPStan. Commits ------- 9f853f3 [Routing] revert the return type for UrlGeneratorInterface::generate to remove null
The
UrlGenerator
has always been able to returnnull
. Many tests assert this for many years but the interface actually always only allowed astring
return.Examples for tests:
So I think I would not consider this change as a BC break but rather a doc fix because it seems like
null
has always been an accepted return value.