Alternative Proposal for Segment handling #174
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@kocsismate, @TimWolla since it would mean another wall of text I choose to create this POC instead. in response to https://news-web.php.net/php.internals/129595
TL;DR:
UriPathTypeEnumUriPathSegmentsclass (Naming is not that important for now)The
UriPathSegmentshas 2 properties:$type(UriPathType::AbsoluteorUriPathType::Relative) and the$segments(an array list of decoded path segments).Unless I am mistaking or forgetting something both URL and URI encode and decode path the same way. So in this case having 2 class is meaningless.
The path is always reconstructed safely using both properties (we stay away from how C# does its representation).
The class could/may be improved with more methods but for now I added the following methods:
Of note in the case of a class created from
Url::getPaththere should be differences between bothtoRawStringandtoStringstring representation but it can for the path created fromUrl::getRawPath.IMHO this version improve DX and avoid adding with* and get* methods on the URI/Url class because not all Url/Uri uses segments good examples includes the URI/URL with the
dataor theurnscheme.