-
Notifications
You must be signed in to change notification settings - Fork 379
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
[Dependency Injection] [Filter] Implement filter service abstraction for creating images #922
Conversation
…eBundle into rvanlaarhoven-patch-1
Updating 2.0 with corrections from 1.0
removed html coverage generation updated readme info urls
Service/FilterService.php
Outdated
* @param array|null $runtimeFilters | ||
* @return \Liip\ImagineBundle\Binary\BinaryInterface | ||
* @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException | ||
*/ |
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.
All doc blocks need their CS fixes such that they are ordered param
, throws
, return
, each type is separated by a two newlines, and have their param
variables aligned. We also use short class names, even if they aren't used in the current file a and require an additional use
statement.
/**
* @param string $path
* @param string $filter
* @param array|null $runtimeFilters
*
* @throws \Liip\ImagineBundle\Exception\Imagine\Filter\NonExistingFilterException
*
* @return \Liip\ImagineBundle\Binary\BinaryInterface
*/
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'm confused regarding using short class names, as you said the complete opposite in this comment: https://github.com/liip/LiipImagineBundle/pull/908/files/f9cb8243475a1e492cb77ac5e639d306381fe9a8#diff-3edb79e074a2b20890b43396b316b5d3L60
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.
Or is the short class name only used for @param
but not for @throws
and @return
?
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.
My bad, regarding the referenced comment, I thought that was a @covers
which is where we've been adding leading backslashes. That, too, should be fixed, I just skimmed over what it was too fast. :-(
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.
We have a php-cs-fixer
require-dev
requirement as well as the associated style settings; I would just run that, which will take care of everything but the FQCNs.
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.
Erm, looks like our fixer rules are out of date and most of them are skipped, so that isn't a sure-fire bet either...
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.
Is this what you mean? 4bce009
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.
Short of the FQCNs that still exist, yes.
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.
The @cover
instances should be the only examples of FQCNs (and I don't know that we have a real policy for @see
yet), but we do always use short names for method doc blocks
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.
Ah yes, that makes sense. Thanks.
The RST documentation (which is what is pushed to Symfony's online documentation website) requires changes and additional pertinent to this change, as well. The general intention (and the vast majority of implementation) looks really great. I'll try to provide a full review by the end of this weekend with any comments I have. Thanks for this; it ticks off one of the larger TODO items from our |
I've merged this PR with master so I could use short array syntax again 🎉 |
Lets wait until #926 will be merged into 2.0 |
Also closes #806 |
Not sure what's going on with #926 since it's closed but not merged? |
The |
You need apply your service also here https://github.com/liip/LiipImagineBundle/blob/2.0/Async/ResolveCacheProcessor.php |
All branches up to date. |
I've updated the |
Does anyone have any thoughts on the CQS vs Temporal Coupling discussion in my initial PR message? The more I think about it, the more I think I'd rather have a CQS violation than temporal coupling, so instead of one method to query what the URL would be and a command to create the image, create one find-or-create method that creates the image if it doesn't exist and then return the URL, or if the image already existed just return the URL. |
Yes, I absolutely prefer this approach. |
By coupling the creation of the filtered image to resolvig the URL of the resolving image the use case of requesting the URL of a filtered image that has not been created yet (temporal coupling issue) is no longer possible. The current implementation breaks CQS, but this is not as bad as the previous temporal coupling.
Done. This approach makes more sense for this project than the previous approach 😃 |
Could I get a review on this one please? |
Nice PR, can anybody review? |
LGTM |
This looks fine to me as well. I've been focused on getting |
This PR has been open for a long time (since May of this year). |
@rpkamp Thank you for the contribution. |
This PR splits all the image manipulation from the ImagineController and ResolveCacheCommand classes to a new FilterService class, which was on the roadmap for 2.x:
The advantages of this are:
This PR is missing tests for the FilterService class, but I intend to add those once everyone agrees on a general direction of this PR. I did test the functionality in the browser (by using it in a separate test project) and that works as expected.
Discussion
In the FilterService the method
createFilteredImage
is closely tied togetUrlOfFilteredImage
, but the first is to create the image and the latter is to retrieve the URL of the created image. Same thing goes forcreateFilteredImageWithRuntimeFilters
andgetUrlOfFilteredImageWithRuntimeFilters
.I split these out because of the CQS principle, but have now introduced a temporal coupling between the two. A more pure CQS approach would be to generate a URL first and then pass it to
createFilteredImage
as the desired URL for the image. However, it would be a mayor overhaul at this point to accomplish that, if indeed it is at all possible.An alternative could be to let
createFilteredImage
return the URL of the resulting image (whether is was obtained from cache or not) in kind of find-or-create pattern way. This breaks CQS, but might be easier to understand and is less verbose in usage because one would only need one call instead of two to create a filtered image and obtain its URL.