-
Notifications
You must be signed in to change notification settings - Fork 53
Add AddPathPlugin always_prepend option #74
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
Conversation
I'm open to suggestions for an alternative to the smart name! |
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.
looks good to me, apart from my style nitpicks. i am not super happy with "smart" but can't think of a better name. i can live with "smart" :-)
* @param UriInterface $uri | ||
* @param array $config { | ||
* |
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.
please remove the extra blank line
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.
Looks like StyleCI wants this extra blank line.
src/Plugin/AddPathPlugin.php
Outdated
* @param UriInterface $uri | ||
* @param array $config { | ||
* | ||
* @var bool $smart True will prepend path only if request path does not start with path to add. |
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.
i am somehow confused by the wording. maybe "Set to true to only prepend the path only if the request path does not start with that path already."?
src/Plugin/AddPathPlugin.php
Outdated
$prepend = $this->uri->getPath(); | ||
$path = $request->getUri()->getPath(); | ||
|
||
if (!($this->smart && substr($path, 0, strlen($prepend)) === $prepend)) { |
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.
can we rewrite this to if (!$this->smart || !substr(...))
? i feel that is more readable.
CHANGELOG.md
Outdated
@@ -2,6 +2,11 @@ | |||
|
|||
## Unreleased | |||
|
|||
### Added | |||
|
|||
- Add the `$smart` option to `AddPathPlugin` to prepend path only when required. |
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.
lets write this 'smart'
instead of $smart
About the smart name. We can also reverse the boolean meaning and so the behavior (and of course change the default value). Maybe it could help to find a better name. EDIT: what about |
I like that better. |
src/Plugin/AddPathPlugin.php
Outdated
$prepend = $this->uri->getPath(); | ||
$path = $request->getUri()->getPath(); | ||
|
||
if (!$this->smart || substr($path, 0, strlen($prepend)) !== $prepend) { |
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.
This only consider the case where $prepend
is the beginning of $path
. Is that the only case we want?
In your case on Gitlab, you do not want to prepend if a absolute URL is used. IMHO, that logic should only be in BaseUriPlugin.
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.
I did this way to be more consistant with AddHostPlugin
which owns the replace logic.
To get back to my use case, it's about using Link
header href attributes. As of https://tools.ietf.org/html/rfc5988 §5.1 this IRI can be relative so I'm not sure that in a future release gitlab will send relative IRIs.
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.
But maybe I'm wrong with the client design and the API path (/api/v3) should be hardcoded in the abstract api class and so, I just need to use the AddHostPlugin
as the user will only configure it's gitlab instance domain.
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.
But maybe I'm wrong with the client design and the API path (/api/v3) should be hardcoded in the abstract api class
Yeah, maybe.. :/
Or in every endpoint..
Though. This PR is still useful.
How about |
Hm, rereading the initial comment not sure what we prepend here. Always prepend sounds a little weird to me. |
The AddPath plugin prepends the current path with a predefined value. The idea is that if the predefined value is "/foo/bar" then we should not prepend that to an url like "/foo/bar/whatever" since it already contains "/foo/bar". |
If prepend is an issue, I can name the option |
No, my issue is with Don't know if there is a better name for it though. |
Something between “always_prepend” and “prepend_even_if_uri_start_with_prefix” would be good.
Regards
Tobias Nyholm
… On 8 juni 2017, at 17:14, Márk Sági-Kazár ***@***.***> wrote:
No, my issue is with always. Despite the word, it does not express the conditions when it matters. Of course we can document it properly, but very likely the next time I meet the config value I will just not remember what it was and look it up again.
Don't know if there is a better name for it though.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#74 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABN1RgRvgKk9WapV7jvKlNbBMTM69EcPks5sCA_wgaJpZM4NxjxN>.
|
Exactly 😂 |
Fabien listen to propositions. |
Name it |
Closing because no longer required for https://github.com/m4tthumphrey/php-gitlab-api. |
@sagikazarmark @Nyholm Can we re-open this issue? If you try to restart a failed API call by calling |
What is the exact use case behind adding a path prefix to a path that already has the prefix anyway? I can not imagine any. |
This allow to make the
AddPathPlugin
smart. By smart I mean to not prepend the configured URI path to the request URI if already present. This behavior is disabled by default to keep code BC.The
BaseUriPlugin
now has a third optional constructor argument to configure the underlyingAddPathPlugin
.This is required for https://github.com/m4tthumphrey/php-gitlab-api which has a base URI set to
https://example.gitlab.com/api/v3
but is also used to follow paginationLink
headers uri which already have the base URI configured.To do