The Routes.php file has undergone a lot of churn and stayed pretty much untouched while major internal changes have taken place (like the introduction of the ResourceType class). In addition, multiple security issues have touched this code, modifying it with the most minimal set of changes at the cost of some code duplication.
This issue should introduce no new concepts. It should be "pure" refactoring.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | interdiff-8-10.txt | 1.08 KB | gabesullice |
| #10 | 2971562-10.patch | 14.55 KB | gabesullice |
| #8 | interdiff-2-8.txt | 3.94 KB | gabesullice |
| #8 | 2971562-8.patch | 14.52 KB | gabesullice |
| #2 | 2971562-2.patch | 15.07 KB | gabesullice |
Comments
Comment #2
gabesulliceLet's see what testbot thinks. Doesn't need a review yet.
Comment #3
gabesulliceAll tests passed, no new CS violations. Ready for review.
Comment #4
wim leersYou said "no reviews" but I couldn't resist a quick scan 😅
I sure like the look of this.
TIL you can add something to all routes in a collection 😲
Comment #5
wim leersOh haha, and then you suddenly did want reviews! On it :)
Comment #6
gabesulliceThis could be static.
Comment #7
wim leers194 insertions, 102 deletionsI'd like to see this delete more than it inserts.
Nit: Missing
@vartypehint.What if we instead use
RouteCollection::addPrefix()? Then both the::getRoutesForResourceType()helper method and the "entry point" one can be blissfully unaware of the prefix!Nit: Inconsistent comments.
Why?
These calls can be chained.
But … we control whatD'oh, for all routes except the "collection" one, we indeed need this.parametersoption gets set, and it's always the same.Still, this is actually more complex than what we have today.
AFAICT
getIndividualRoutesForResourceType()(which does the "individual", "related" and "relationship" routes) actually could just callRouteCollection::addOptions()?Chaining.
Comment #8
gabesullice7.1: Yes, absolutely. That's a primary motivation. Also, this will hopefully set us up to simplify or factor away
RequestHandler.7.2: Hm, that's an interesting metric for this. I'll look again, but that won't be in this interdiff.
7.3: Added.
7.4: I had exactly this. But there's a bug in the Symfony router that ends up adding a trailing
/to the collection and entry point routes, making them inaccessible.7.5: 🦅👁
7.6: Because they're fundamentally different. While they share a common path, that's where the similarity ends. One is read-only, doesn't need CSRF and I think "belongs" with the "individual" routes (
createIndividual). I didn't make that change because I promised a "pure refactoring" perhaps that's worth just doing here though? Either way, comment expanded.7.7: Eh, I really hate chaining for the same reason arrays need trailing commas.
7.8: Ah, you're right, maybe that'll help the add/remove stat.
7.9: Like 7.7, will change if it's a deal-breaker for you.
Comment #10
gabesulliceWhoops, forgot my own recommendation from #6 and borked the change.
Comment #11
wim leers🤦♂️
7.7/7.9: heh, fair :) Keep it as-is, definitely not a deal breaker, just a nit.
Better, but still not net-negative.
Trying to simplify further.
Comment #12
wim leersIt seems I can't reproduce this bug. Let's see.
Comment #14
wim leersSo there's only a problem with the "entry point" route due to the Symfony bugs that @gabesullice mentioned. Because Symfony inconsistently trims trailing lead slashes. Basically a
/route that gets a prefix such as/foobarends up with/foobar/, and there's nothing you can do about it.Still, we can remove some of the path prefix handling.
(Now down to 174 insertions, 102 deletions.)
Comment #15
wim leersInterestingly, it seems nobody has reported this bug at https://github.com/symfony/symfony/issues?q=is%3Aissue+routecollection+a....
OTOH it seems like this is intentional; the intent is to preserve any trailing slashes. So I can't simplify #14 further wrt path prefixing.
Comment #16
wim leers\Drupal\jsonapi\Routing\Routes::authProviderList()and the injected service seem like they could go away. Since that code was written, #2308745: Remove rest.settings.yml, use rest_resource config entities happened (introduced a useful container parameter), and e.g. #2825204: REST views: authentication is broken started using it.Next, the
::create()implementation is pretty long and atypical. That can be simplified.Finally, one of the reasons the diffstat is not looking too great is because this is adding several multi-line todo comments. I moved those into issues: #2971649: Make '_is_jsonapi' route option a route default + #2971652: Separate the collection route from the individual resource creation route. And because these are optional enhancements, not must-haves, and their need is pre-existing rather than being introduced here, I'm removing the
@todocomments altogether. Plus,@todos are easily ignored, open issues are not.New diffstat:
173 insertions, 134 deletions. Still net growth. Most of that is of course in the form of comments — Drupal's documentation standards/requirements are quite onerous.I don't see how this patch can be simplified further.
I can see how this patch makes things more consistent, and how it helps ensure things will remain more consistent. That being said, I'm not sure this is really simpler. Basically: the "get route" helper methods make things more consistent, but then due to Symfony routing system weirdness, we need several unfortunate work-arounds (
addRouteParameter(), passing path prefix down to the first level of helpers) that undo some of the gained simplicity.I don't have a strong opinion, if others do, I'm fine with this.
Comment #18
gabesulliceAwesome. Since this is just needing to update a unit test and fix a CS violation, marking RTBC if tests pass.
Comment #19
gabesulliceComment #21
wim leers