Inflectors
What are inflectors ?
Certain classes are used often by others.
If we needed to bind them using the container manually that would be really time-wasting and that's why use inflectors to make that job for us.
Inflectors are automatic binder that inject a dependency to a class using a predefined method when the class in question is implementing a class.
By default, we have the following inflectors available :
Dependency | Interface | Trait | Description |
---|---|---|---|
prefix | Inject the prefix from the plugin | ||
Inject the WordPress hook dispatcher | |||
None | Inject event manager. |
How to add my own inflectors ?
Registering inflectors is possible at the level from Service Providers.
For that the service provider will have to first implement the interface LaunchpadCore\Container\HasInflectorInterface
and the trait LaunchpadCore\Container\InflectorServiceProviderTrait
.
This will provide access to a new method get_inflectors
which will have to return the binding between the interface, the method used to inject the dependency and the arguments from that method:
Last updated