-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Adding the UriTemplate class to implement RFC6570 #153
Conversation
d59ac9b
to
c7fa727
Compare
the test should be adapted to use https://github.com/uri-templates/uritemplate-test |
dd17e57
to
d8a1a13
Compare
@kelunik would you mind reviewing this PR which adds Of note:
the remaining issue before merging is how the following templates should be handle
Currently they will throw because of the presence of a When regarding other implementations, the second example always throws but not the first one does not 🤷♂ IMHO they should either both throw or they should not. thanks in advance of the remarks and suggestions 😉. |
I haven't read the RFC nor used URI templates, yet, but I always wanted to do that. I guess you're mainly looking for an API review, as the correctness is pretty much covered by existing test suites? Regarding your open question, I guess they should both throw, because it's likely a mistake. Isn't |
Indeed it' mainly a API review... for the |
If it's not a valid placeholder and thus not replaced, it'll end up in the expanded URI, no? |
Currently with my implementation <?php
$template = 'http://example.com/{foo';
$uriTemplate = new UriTemplate($template);
$uriTemplate->getVariableNames(); //returns []
echo $uriTemplate->expand(['foo' => 'bar']), PHP_EOL;
//this passes and produces http://example.com/{foo
$template = 'http://example.com/}foo/{foo}';
$uriTemplate = new UriTemplate($template);
$uriTemplate->getVariableNames(); //returns ['foo']
echo $uriTemplate->expand(['foo' => 'bar']), PHP_EOL;
//this passes and produces http://example.com/}foo/bar but <?php
$template = 'http://example.com/{foo/{foo}';
new UriTemplate($template);
//throws on instantiation |
@kelunik after a good night sleep and reviewing other implementations again, I've decided to go the route of being more strict (ie ... all the examples I gave you above are now ALL throwing exception). The reason being that:
This should resolve my last issue IMHO |
Enhancement
Following the fact that Guzzle 7.0 will drop its
UriTemplate
implementation see #2240. I'm adding one to the URI package based on theUriTemplate
class found in Guzzle 6.5 but with 2 main differences:http_build_query
UriTemplate::expand
method. As such the latter method does not have a$template
argument.Here's the public API methods apart from the getter and wither.
The class and its API are based on: