-
Notifications
You must be signed in to change notification settings - Fork 378
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
[1.0][CacheResolver] Resolver get rid of get browser path #284
[1.0][CacheResolver] Resolver get rid of get browser path #284
Conversation
@@ -120,7 +119,13 @@ protected function getResolver($filter) | |||
*/ | |||
public function getBrowserPath($path, $filter, $absolute = false) | |||
{ | |||
return $this->getResolver($filter)->getBrowserPath($path, $filter, $absolute); | |||
//call it to make sure the resolver for the give filter exists. | |||
$this->getResolver($filter); |
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.
There is no use to this behavior. The resolve method will try to retrieve the resolver anyway and throws an exception if none is applicable.
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.
That's the only thing left, as far as I can see. What's the benefit of this line?
The only case I can see, would be calling an invalid filter from a template. The issue I see: the whole template would not be rendered with this line in place. Without this line, the template would be fine as it and only contain an invalid URL to an image (via generateUrl
).
|
@LouTerrailloune The
Did you actually refer to the
The URL returned by the |
if ($filteredImagePath instanceof Response) { | ||
return $filteredImagePath; | ||
if ($url = $this->cacheManager->resolve($originalImagePath, $filter)) { | ||
return new RedirectResponse($url, 301); |
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 don't like this. It's cleaner than before, but now the resolve
method is responsible of detecting whether the given path has been stored within this resolver and resolve the given path to a URL utilising the resolver.
I would prefer a new method isStored
or something to decouple the two facts.
The controller then can distinguish between an already stored image and a to-be-stored one.
This will also remove the ambiguous return value of the Resolver::resolve
method. It's always string: the URL. While the new method will take care of the previous null
return value, question would result in a false
of isStored
.
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 think it is a good idea in general. What should happen if one call resolve when image is not stored yet? I would say an exception.
Yes, typo.
Most of the time, the url of the cached picture is returned by
May be I have a resolver that store filtered picture (cropped, watermarked, etcc) into a database. In that case, the filterAction is alway hit and |
Regarding my use case about database cache, we need to keep
In |
That's fine because the bundles
If you got a |
This is what I want to do. However, in this PR, |
Yes that's fine, you will have to move some logic around, because you mixed up the resolver with the controller. That's an issue of the old version. |
So to sum up all the discussion:
Do I miss something? |
@LouTerrailloune we should definitly think of the cases when the image stored in database or something like that. But my main goal right now to decouple things and clean the bundle a bit. Later we can come back and rethink our use case. |
Not as far as I can see. |
rebased against lates resolver-do-not-expose-target-path branch |
For some reason I currently can't create a PR with Github, it's not recognising the branch. I added the |
PR is now available, created another branch which is recognised by Github. |
add ResolverInterface::isStored
I think it is almost fine but I would like to review it a bit more today in the evening to make sure I dont miss\broke anything |
Fine by me, let me know :-) |
@havvg I fixed WebPathResolver. It was not return string on resolve always as interface demand. Also updated UPGRADE.md |
* @param string $path The resource path to convert. | ||
* @param string $filter The name of the imagine filter. | ||
* | ||
* @return string | ||
*/ | ||
abstract protected function getFilePath($path, $filter); | ||
protected function getFilePath($path, $filter) |
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 move this logic back into WebPathResolver. It's bound to the web root.
@havvg done |
@havvg ping |
…rowser-path [1.0][CacheResolver] Resolver get rid of get browser path
Thank you! |
This PR is attemp to address @LouTerrailloune comment.
It is based on #282 PR so please consider reviewing and merging that one first.
To say briefly about changes:
resolve
method can return NULL which means we dont have a cache yet and a string. String is an url where the image located.getBrowserPath
was removed.getBrowserPath
now use resolve method to find a cached image url. If it fails it generates an url of filter action.