-
Notifications
You must be signed in to change notification settings - Fork 384
Add support for alternatiwe image formats like webp and avif #1651
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
base: 2.x
Are you sure you want to change the base?
Changes from all commits
e75dca3
d1451d6
6f012fa
ba61f54
d493ff6
7f8ffb4
d32251c
0c62ca5
d49844a
bd0a357
dae2888
56072b4
75cc4a9
4fad8f7
f7fd821
5e3e46e
5909f3a
07e5821
d7be781
45c1b4a
0e2f735
5f62a74
eeb6255
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,5 @@ | |
| /Tests/Functional/app/web/media/cache | ||
| /var/ | ||
| /vendor/ | ||
| /.idea/ | ||
| /.junie/guidelines.md | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please do not add local dev environment specific things to the gitignore. use your global gitignore on your workstation for those. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,30 +55,39 @@ class CacheManager | |
| protected $defaultResolver; | ||
|
|
||
| /** | ||
| * @var bool | ||
| * @var array|bool | ||
| */ | ||
| private $webpGenerate; | ||
| private $alternativeFormats; | ||
|
|
||
| /** | ||
| * Constructs the cache manager to handle Resolvers based on the provided FilterConfiguration. | ||
| * | ||
| * @param string $defaultResolver | ||
| * @param bool $webpGenerate | ||
| * @param string $defaultResolver | ||
| * @param array|bool $alternativeFormats | ||
| */ | ||
| public function __construct( | ||
| FilterConfiguration $filterConfig, | ||
| RouterInterface $router, | ||
| SignerInterface $signer, | ||
| EventDispatcherInterface $dispatcher, | ||
| $defaultResolver = null, | ||
| $webpGenerate = false | ||
| $alternativeFormats = [] | ||
| ) { | ||
| if (\is_bool($alternativeFormats)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we default the parameter to [] instead? otherwise not setting alternative formats triggers a deprecation |
||
| @trigger_error(\sprintf('Passing a boolean as the second argument to %s is deprecated since LiipImagineBundle 2.x and will be removed in 3.0. Pass an array of alternative formats instead.', __METHOD__), E_USER_DEPRECATED); | ||
| $alternativeFormats = $alternativeFormats?["webp" => ["generate" => true]]:[]; | ||
| } | ||
|
|
||
| if (!is_array($alternativeFormats)) { | ||
| throw new \InvalidArgumentException('The second argument to '.__METHOD__.' must be an array or boolean.'); | ||
| } | ||
|
|
||
| $this->filterConfig = $filterConfig; | ||
| $this->router = $router; | ||
| $this->signer = $signer; | ||
| $this->dispatcher = $dispatcher; | ||
| $this->defaultResolver = $defaultResolver ?: 'default'; | ||
| $this->webpGenerate = $webpGenerate; | ||
| $this->alternativeFormats = $alternativeFormats; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would normalize this to have the property only accept array and translate false to |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -108,15 +117,23 @@ public function addResolver($filter, ResolverInterface $resolver) | |
| */ | ||
| public function getBrowserPath($path, $filter, array $runtimeConfig = [], $resolver = null, $referenceType = UrlGeneratorInterface::ABSOLUTE_URL) | ||
| { | ||
| $shouldGenerateAlternative = false; | ||
| foreach ($this->alternativeFormats as $formatConfig) { | ||
| if (isset($formatConfig['generate']) && true === $formatConfig['generate']) { | ||
| $shouldGenerateAlternative = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!empty($runtimeConfig)) { | ||
| $rcPath = $this->getRuntimePath($path, $runtimeConfig); | ||
|
|
||
| return !$this->webpGenerate && $this->isStored($rcPath, $filter, $resolver) ? | ||
| return !$shouldGenerateAlternative && $this->isStored($rcPath, $filter, $resolver) ? | ||
| $this->resolve($rcPath, $filter, $resolver) : | ||
| $this->generateUrl($path, $filter, $runtimeConfig, $resolver, $referenceType); | ||
| } | ||
|
|
||
| return !$this->webpGenerate && $this->isStored($path, $filter, $resolver) ? | ||
| return !$shouldGenerateAlternative && $this->isStored($path, $filter, $resolver) ? | ||
| $this->resolve($path, $filter, $resolver) : | ||
| $this->generateUrl($path, $filter, [], $resolver, $referenceType); | ||
| } | ||
|
|
||
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 don't change this setting.
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 was not addressed