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 :

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:


    /**
     * Returns inflectors.
     *
     * @return array[]
     */
    public function get_inflectors(): array
    {
        return [
            MyDependencyInterface::class => [
                'method' => 'set_my_dependency',
                'args' => [
                    MyDependency::class,
                ],
            ],
            MySecondDependencyAwareInteface::class => [
                'method' => 'set_my_second_dependency',
                'args' => [
                    MySecondDependency::class,
                ],
            ],
        ];
    }

Last updated