-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
FEATURE: introduce UriHelper
to work with query parameters
#3316
FEATURE: introduce UriHelper
to work with query parameters
#3316
Conversation
207acc6
to
c5299df
Compare
Very nice idea ... how about using named variadic arguments instead of an array to $this->someUriBuilder->uriFor(...)->withQueryParameters(q: 'search term'); The only downside of extending the psr uri imho would be that a future psr-version might define the same method with a different signature. Bit theoretical and we would find a way (migration) around that. |
Also:
|
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.
Thanks for the mini adjustments, +1 by reading
how about using named variadic arguments instead
IMO that could be weird with nested arrays. And it won't work if the param name contains invalid characters (like -
)
The \Neos\Http\Factories\UriFactory should return the Neos Uri in that case and it might make more sense to
+1
Why not extend \GuzzleHttp\Psr7\Uri as those guzzle classes are used in the UriFactory curently anyways
I would vote against that because it adds an explicit dependency and makes us more vulnerable to future changes of the upstream implementation.
Forwarding all method calls to the wrapped implementation is awkward, so I had the same reflex. But I think it is not an actual issue here and still better than inheritance
Bastian is right ... even though i really like variadics |
Which was introduced via neos#2793
Yeeeeeah, but then how do we deal with interface compatibility, because suddenly every place we use this we shouldn't / can't rightfully annotate UriInterface anymore. I would rather prefer to go the guzzle route and implement static methods for this. It's a simple enough operation. |
@kitsunet Is your suggestion to not re-add the SomeClass {
public static function addQueryParameters(UriInterface $uri, array $queryParameters): UriInterface;
} ? I don't think that's a bad idea.. For the regular use cases (i.e. Fusion, ...) we can add corresponding helpers |
Yes! Exctly, guzzle psr7 has a couple of helpers that do similar things (nothing for GET params though) but I find that super fine for such syntactic sugar. |
btw: It does https://github.com/guzzle/psr7/blob/2.6/src/Query.php#L71 but I prefer the suggested signature for brevity ( |
Id be find also with a utility, even though its not that easily usable, but less pain on our end. Also we can simply document in the uribuilders that this utility exists and how to use it ;) UriHelper::withAdditionalQueryParameters($this->someUriBuilder->uriFor(...), ['q' => 'search term']); will implement this accordingly ;) And thanks for your extensive feedback! |
Okay added a |
d31684d
to
95537db
Compare
Neos\Flow\Http\Uri
as psr uri wrap with toolsNeos\Flow\Http\UriHelper
to work with query parameters
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.
totally fine by 👀 ... also no risk in here
Lol i just found out we already have a |
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.
Nice one, +1 by reading.
I'm wondering whether this could be used as an Eel helper, too?
(implementing ProtectedContextAwareInterface
and allowing string
as input)
That way we could use it something like:
uri = Neos.Fusion:UriBuilder {
// ...
@process.addQuery = ${Neos.Flow.uri.withAdditionalQueryParameters(value, {foo: 'bar'})}
}
or was the plan to extend the built-in prototype implementations to support this?
in any case, this can be tackled in separate PRs ofc
Wait a second i think i wanted to add the method to
as otherwise we would have two thanks for the plenty +1 but i prefer to merge my own prs :D |
The followup which was due since some time but i was to scared to jump into another rabbit hole: #3336 |
Neos\Flow\Http\UriHelper
to work with query parametersUriHelper
to work with query parameters
FYI: This pr was refactored again via #3336
While working on #2744 and also neos/neos-development-collection#4552 we always came to the conclusion that the
$queryParameters
merging of the psr uri is limited.This introduces a utility to do this:
and allows us to remove any $queryParam logic from the uribuilder(s)
Upgrade instructions
Review instructions
Checklist
FEATURE|TASK|BUGFIX
!!!
and have upgrade-instructions