This is essentially a sub-task of #1888424: Make Drupal's URL generation logic available to HttpKernel, and minimize code repetition/divergence, which we decided should be broken up into 2 issues - one to deal with incoming path processing (this one) and one to deal with the outgoing (url generation) side of things. The original issue will be kept for the outgoing side and will build on the work done here.
The goal here, then, is to turn the process for resolving the incoming path to a system path into something that can be mirrored on the outgoing side. The current set-up uses a series of request listeners to perform the necessary futzing:
- one for urldecoding the path
- one that resolves an empty path to the system path for the front page
- one for stripping off the language prefix if there is one
- one for converting an alias to a system path
This patch replaces the series of request listeners with a single listener that uses a PathProcessorManager to resolve the system path. Individual processors are registered to the manager with a priority indicating where in the sequence they should come, and the manager goes through them in sequence to return a fully processed path.
Comment | File | Size | Author |
---|---|---|---|
#10 | 1910318.path_futzers.10.patch | 29.76 KB | katbailey |
#10 | interdiff.txt | 14.17 KB | katbailey |
#7 | 1910318.path_futzers.7.patch | 20.44 KB | katbailey |
#4 | 1910318.path_futzers.4.patch | 20.46 KB | katbailey |
#4 | interdiff.txt | 14.37 KB | katbailey |
Comments
Comment #1
Crell CreditAttribution: Crell commentedWe already went over this patch extensively in the parent issue, so there's not much to say. It all looks great. :-) The line above is really my only remaining question mark.
All of the Symfony logic assumes a path that has a / prefix. Drupal has always assumed a path without prefix. That means currently we have a number of these transition points around the code where we have to translate from path prefixed to not path prefixed.
At what point do we rip those out and just use a / prefix everywhere, and avoid this fun potential bug? I don't know if this is a good time to do that, but it's worth asking if we should just tell path processors to assume a /-prefixed path, rather than an unprefixed path as Drupal has done in the past.
Saving that for a later system-wide issue is fine, but this seemed a reasonable place to bring it up.
Other than that question this should be RTBC.
Comment #2
sunCould we move these into a Drupal\Core\HttpKernel namespace? (with or without additional PathProcessor subnamespace)
I'm not sure I can make sense of an independent and own PathProcessor component — the facility always seems to be bound to the Request/Subrequest/Response processing stack.
Can we rename "incoming" to "inbound"?
Inbound + outbound are slightly clearer and more direct opposite terms than Incoming and Outgoing (or whatever term you had in mind).
Thinking ahead of time, would it make sense to put all the inbound path processors into a separate ./Inbound subdirectory?
So that we can possibly complement that later on with an ./Outbound subdirectory?
Can we move this into a \HttpKernel subnamespace; i.e.: Drupal\language\HttpKernel\PathProcessorLanguage?
Comment #3
Crell CreditAttribution: Crell commentedI don't believe we have a Drupal\Core\HttpKernel namespace yet, do we? I'm not against such a thing in concept, but I don't think this is the place to introduce it. If we were to add such a thing, there are other classes that might migrate there, too. I'd prefer to punt on that.
The rest of the comments from #2 seem reasonable.
Comment #4
katbailey CreditAttribution: katbailey commentedIt's not inconceivable that we might have classes that implement both the inbound and the outbound interface - I'd rather wait until we've figured out the outbound side and then we can see if this makes sense.
The only changes I've made here are 1) use "incoming" instead of "inbound", and 2) move the language path processor into a HttpKernel subnamespace.
Comment #5
katbailey CreditAttribution: katbailey commentedOh, and about dealing with the leading "/" on paths, my inclination is to say let's leave that for a follow-up issue - but that may very well just be my laziness talking, so if anyone feels strongly that it should be done here I'll add in that change.
Comment #6
Crell CreditAttribution: Crell commentedThis should get renamed to inbound, too, as should incomingProcessors.
Ibid.
Other than that, this is good to go. I'm fine with punting on the / for now and making that a dedicated issue.
Comment #7
katbailey CreditAttribution: katbailey commentedOK, this time I really do promise there are no more instances of "incoming" in the patch. Or "manipulate" for that matter.
Comment #8
Crell CreditAttribution: Crell commentedLet's do. :-)
Comment #9
suns/inbound_path_processor/path_processor_inbound/g
Minor, so we can also do it in a follow-up patch/issue.
What concerns me with this is the resulting negative DX effect of "random string identifier that apparently denotes a service" + "random string identifier that apparently denotes a tag that is related to a service with a similarly random string identifier".
Only the original author understands that kind of API design.
Unless I'm terribly mistaken, this sub-array initialization isn't needed in PHP5 anymore.
That looks funky.
It actually exceeds the funky-cool level to an extent at which we should have dedicated a test for the expected result of this sorting algorithm. :)
I briefly looked around, but can't see why the foreach() even exists in the first place? $sorted is always empty?
I already wondered about the priorities in
registerPathProcessors()
at first sight...Can we move the decode processor to 1,000, and move this language futzer to 300? (replacing the current 300 of the decode processor)
Comment #10
katbailey CreditAttribution: katbailey commentedAddressed sun's points, with the exception of:
I'm not sure what you mean. $sorted starts out empty but gets the processors merged into it on each iteration through the various priorities.
I've added a DrupalUnitTest to test the processor manager using incorrect and correct orderings of the processors.
Comment #11
sunI still do not understand why the
foreach()
andarray_merge()
is needed. $sorted always starts out as an empty array, so the elements of $this->inboundProcessors are repetitively added to $sorted, since there is nothing else to merge. The entire effect of that sort method is thekrsort()
only.Anyway...
Comment #12
sunOh. I'm sorry. You're not only sorting, but also flattening the second dimension into the first. Gotcha.
Comment #13
katbailey CreditAttribution: katbailey commented#10: 1910318.path_futzers.10.patch queued for re-testing.
Comment #14
Crell CreditAttribution: Crell commentedBumping priority since this is blocking the generator/outbound merging issue.
Comment #15
catchCan't find anything to complain about, committed/pushed to 8.x.
Comment #17
mbayntonThis comment pertains to a @todo in PathProcessorDecode (which it looks like was inherited from
Drupal\Core\EventSubscriber\PathSubscriber
), but given that this issue is the origin of the @todo's current home, I think this issue is the best venue to begin a discussion:The logic being a
urldecode()
of the path. It should be kept, because controllers aren't the only thing benefiting from this path processor - later path processors do too. This is the reason URL aliases built out of the broader unicode charset work, not an uncommon thing since IRIs are received as RFC3986-encoded strings -- any internationalized URI is in need of this urldecode. Sure, you could go around remembering to decode it in any other current/future path processors as well, but in general I think the above illustrates how having this here will mostly just keep things working as expected for anyone dealing with paths. Thinking to urldecode paths in order to be internationalized is an unneeded gotcha.If that makes sense to others, perhaps a new issue just to remove the comment?