Sometimes you see simple interfaces with a getter and a setter for a specific type of object. Some examples are league/event
‘s EmitterAwareInterface
and league/container
‘s ImmutableContainerAwareInterface
. Also Zend Framework 2 has a ton of *AwareInterface
s like (but not limited to) these:
These packages often come with a reusable trait that gives you pluggable implementations for these interfaces out of the box. For previous examples there are the EmitterAwareTrait
and the ImmutableContainerAwareTrait
.
I find these interfaces useful for setting up an IoC container to automatically “setter-inject” a dependency. With Laravel 5.0+’s container one can configure this:
With league/container
‘s container one can use so called inflectors
:
Now if you resolve any kind of object from the IoC container, it will have an EmitterInterface
(or ImmutableContainer
) object injected for you.
Cheers!
Member discussion