On (Symfony 4) How do I access the Liip Imagine bundle from within PHP code? I found a solution to use the Liip Imagine Cache but I can't get it to work. Two solutions, neither of them work for me. I have absolutely no Idea why.
When I try harmstyler's solution with
$imagineCacheManager = $this->get('liip_imagine.cache.manager');
in my Controller then I get a ServiceNotFoundException
Service "liip_imagine.cache.manager" not found: even though it exists in the app's container, the container inside "App\Controller\MemberController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.
So I tried Alister Bulman's suggestion to inject it manually into a class in the service.yaml but that doesn't work either.
In my service.yaml I have
app.imagine_cache_manager:
class: Liip\ImagineBundle\Imagine\Cache\CacheManager
arguments: ["@liip_imagine.cache.manager"]
In my Controller I have
$imagineCacheManager = $this->get('app.imagine_cache_manager');
which leads me to the same Exception
Service "app.imagine_cache_manager" not found: even though it exists in the app's container, the container inside "App\Controller\MemberController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.
[BTW What I am actually trying to do is: I have members and every member has an image. Creating the member I have an image upload and let Liip create resized images of the main image. When I delete the image or the member, of course I also want to delete the cached images by Liip. That's why I try to get the Liip cache manager to be able to get the cached images paths to be able to delete them. Another approach was to have an Event Listener but this didn't work either for me. I will summarize the Listener approach in another question.]