I have a simple interface,
PurgerInterface that has the methods needed to purge items from a cache backend (Varnish or Fastly). I have some custom configuration (standard
system.xml stuff) that allows an admin to decide which backend they'd like to use (Varnish or Fastly).
I also have an Observer that listens to various events and will purge the appropriate caches. Here is the issue: I would like to inject, in my observer constructor, this purger interface like so:
public function __construct(
Now, the issue is that the concrete implementation of the
PurgerInterface that I'd like injected is dependent on a configuration. If the Varnish backend is selected, I'd like
VarnishPurger injected. If Fastly is selected, I'd like
Now, I'm familiar with other frameworks where you are able to dynamically bind items in the "service container" (I'm thinking Laravel here). Basically the logic / code controlling dependency injection can be interacted with, so when the container asks for a
PurgerInterface I can run some code to check which concrete class I should return, and that is the class that is injected.
So, is this possible?