Conversation
|
@kocsismate, @TimWolla and @nicolas-grekas as always I tried implementing the UriBuilder at least the RFC3986 version of it. Here's an usage example: (new Uri\Rfc3986\UriBuilder())
->scheme("https")
->userInfo("user:pass")
->host("example.com")
->port(8080)
->pathSegments(["foo", "bar"])
->query("a=1&b=2")
->fragment("section1")
->build()
->toString();
// returns https://user:pass@example.com:8080/foo/bar?a=1&b=2#section1I have intentionally remove the My first thoughts are as follow:
Last but not least I wonder why we could not have on the top namespace something like the following: Uri\Builder;
Builder::buildUrl(?Uri\WhatWg\Url $baseUrl = null): Uri\WhatWg\Url;
Builder::buildUrI(?Uri\Rfc3986\Uri $baseUri = null): Uri\Rfc3986\Uri;We would have one builder with two building methods one for each type of URI. Since component are the same. It would probably push validation inside the |
|
Just a very wuick note for now: the implementation is outdated and incomplete quite much, so please refer to the rfc for now which is much more complete. But I agree some questions have to be answered related to the queryparams, especially percent encoding-wise. The rfc should describe all the info needed. |
|
@kocsismate the current implementation is based on the RFC but I did not include the queryParams class. Otherwise everything else is based solely on the RFC. |
|
@nyamsprod sorry, my bad. I thought you were referring to my implementation when you wrote "I checked the test in the implementation" 🙂 |
What are your problems with a mutable builder? Is it its statefulness that prevents it to be dependency injected? I chose it to be mutable because URIs are already immutable, so an immutable builder wouldn't solve the performance penalty caused by the withers. To be fair, Ilija told me that it may be possible to minimize the perf penalty by checking if the return value is used: if not, then there's no need to clone the object (I think this is what he said). If this is possible, then I may be OK with an immutable builder class.
It's just an oversight :) I'll add it to the proposal next time I update it.
Yes, it's fine. I think the most tricky cases are the following (without checking uriparser's behavior, just from the top of my head):
I'm looking forward to your evaluation. P.S. I hate that both WHATWG URL, both uriparser use $uri = new Uri\Rfc3986\Uri("https://example.com?%61bc"); // query is "abc"
$params = $uri->getQueryParams(); // $params now contains [ ["%61bc" => null] ]
echo $params->toString(); // %2561bcDouble-encoding... At least WHATWG's |
|
BTW I've just seen your |
|
@kocsismate I have updated the implementation and added more checks during URI building
and the builder is made mutable, for now, I will hold on commenting on the Query method to let you brainstorm and perhaps come up with an improved design 😉 🤞🏾 Also I added |
Yes, thanks! The more I think the more I believe your |
The "funny part" 😄 I will leave the PR open while you are working on your Query implementation and/or RFC and see if I can add the other part and methods but I Believe the Query is the main difficult part as well as deciding if we really need to pass the complete object to the URI objects or force the developer to choose what he wants as shown in this pseudo code: Uri::withQuery($queryParams->toRfc3968()); // the developer decides
Url::withQuery($queryParams->toRfc3968()); // the developer decides wrongly or not ? it depends
//or
Uri::withQueryParams($queryParams); // the object chooses on behalf of/ or restrict the developer
`` |
a19454b to
02c122f
Compare
dba9dfd to
fbaea9b
Compare
7f11c7f to
1def8ee
Compare
fb86982 to
7fe1674
Compare
497702d to
a82d9f8
Compare
a82d9f8 to
b45218f
Compare
|
@kocsismate I have refactored my PR. It contains only things that can be polyfill so any extra method added to the I was wondering if we should not also include the following methods: Uri\Rfc3986\UriHostType::fromUri(Uri $uri): self;
Uri\Rfc3986\UriType::fromUri(Uri $uri): self;
Uri\WhatWg\UrlHostType::fromUrl(Uri\WhatWg\Url $url): self;To emphasise that the logic is no coupled to the URI object ? And the bonus side effect it that is that they can be introduced via the polyfill 😉 |
No description provided.