Inflectors
Last updated
Last updated
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 |
---|---|---|---|
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 register_inflector
which will be able to register inflectors inside the define
method:
An inflector is always split into two parts:
An interface to recognize classes that we want to execute logic on.
An action to make on that class as injecting a property using a special method.
For that we can pass the interface to the register_inflector
method and then:
If we want to call a method we can use the method add_method
:
-If we want to inject a property we can use the method add_property
:
prefix
Inject the prefix from the plugin
Inject the WordPress hook dispatcher
None
Inject event manager.