-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Allow to configure the imagine class #1615
Conversation
// Will throw an exception if the PHP implementation is not available | ||
try { | ||
new $class(); | ||
} catch (RuntimeException $e) { |
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.
What's the benefit of catching instead of letting it fail?
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.
It will fall back to return Imagine::class; // see #616
@@ -145,6 +147,9 @@ function (string $value): string { | |||
->arrayNode('imagine_options') | |||
->addDefaultsIfNotSet() | |||
->children() | |||
->scalarNode('class') |
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 imagine_options
array gets directly passed to setImagineOptions()
https://github.com/contao/image/blob/dc9e2dc78533c6da1d7d0cf010b0b89b2b5ffd06/src/ResizeOptionsInterface.php#L29 so we should probably not add the class name here.
IMO it would be better to use contao.image.imagine_class
instead.
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 agree
I’m not sure if this is the correct approach. How about keeping the existing compiler pass, removing the class from the services.yml in core-bundle/src/Resources/config/services.yml Line 148 in 864fd03
->getClass() === null ?
public function process(ContainerBuilder $container): void
{
$definition = $container->getDefinition('contao.image.imagine');
if (null === $definition->getClass()) {
$definition->setClass($this->getImagineImplementation());
}
} This way you can simply overwrite the used class in the service definition in your installation. What do you think? |
@ausi 's suggestion looks reasonable to me |
Nope, I disagree here. The compiler pass was wrong from day one that's why I changed it. The class you would like to use is a configuration value. It's exactly the right place to do so and it doesn't need any compiler pass at all. But yes, I can change the key to |
But what if the custom Imagine class you want to use needs a constructor parameter or other injections? IMO the services definition ist the right place for replacing services in your application. |
That means you would need dependency injection and not just set the class as an argument. A completely new (maybe valid) case. Maybe we should generate a service on the fly and assign it as argument to that method? |
I have a better idea, give me a few minutes :) |
Okay, so now you can configure any service you like. This will allow to define your own service in the container (that has other arguments) and configure it here. If you don't configure anything at all, the best solution is chosen for you and aliased. |
@@ -142,6 +142,10 @@ function (string $value): string { | |||
->prototype('scalar')->end() | |||
->defaultValue(['jpg', 'jpeg', 'gif', 'png', 'tif', 'tiff', 'bmp', 'svg', 'svgz']) | |||
->end() | |||
->scalarNode('imagine_service') | |||
->info('By default Contao tries to take the best Imagine service out of Gmagick, Imagick and Gd (in this order). If you would like to use a different service, configure the service id here.') |
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.
When will this be displayed?
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.
config:dump-reference
:)
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.
Nice. However we don't have this for any other parameter, therefore I would prefer to remove this from this PR and to create a separate PR which adds descriptions for all parameters. WDYT?
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.
Nah, it belongs to this PR. Just add the info in another commit :)
Ok. Let's see what @ausi says and then merge this. |
I still think that the services definition is the right place for replacing services in your application. We do that in Contao for example with the translator service. Every developer that is familiar with Symfony knows how to do that: services:
contao.image.imagine:
class: Imagine\Gd\Imagine To get knowledge of the configuration value you need to read the documentation first. My suggestion from #1615 (comment) would solve your issues too, right? |
I don't like that. I don't want to configure things in my |
But how do you configure which translator class should be used be the Symfony translator for example, or any other service? |
No idea, it's not part of my problem at the moment 😄 The way this PR implements the service you choose is the same as it's done in thousands of bundles. I don't see the issue here. There's always many ways to achieve the same thing but this one is the one I like best. |
That is not the same to me. Overriding the application is one thing, setting configuration is a different thing. Manually defining your Imagine class is a configuration that makes sense, because people might prefer one over the other. Therefore, there should be a configuration so set it. It's like settings the JPEG quality, you could do that using a compiler pass and change the service argument, but that's just unnecessarily cumbersome. We want people to configure their Imagine service, if they know which one they can use on their server. Same as with the Doctrine server version. You should configure it, but if you don't the system tries to detect the current version. |
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.
K, I’m convinced then 🙃
Thank you @Toflar. |
…#1615) Description ----------- See https://developers.google.com/analytics/devguides/collection/analyticsjs/cookie-usage Commits ------- 08212655 Add Google Analytics ga.js Cookies to StripCookiesSubscriber 3716fcde Update StripCookiesSubscriber.php a05ff52c Update StripCookiesSubscriber.php
Right now you cannot configure the desired
Imagine
class. This has two major drawbacks:Imagick
is installed on your system but it's broken somehow, you are lost. You cannot switch toGd
without adding another compiler pass.Imagine
implementation you cannot use that without adding another compiler pass.This PR allows you to configure the class very easily: