qunity/dependency-injection

Qunity DependencyInjection


License
MIT

Documentation

Qunity DependencyInjection

Dependency injection design pattern engine.


For basic use you need (dependencies are injected through the class constructor):

  1. Initialize the DependencyInjection class by passing in an array of processor configurations. Minimum configuration example:

    DependencyInjection::getInstance([
        ProcessorRewriteClasses::ID => [
            'sort' => 100,
            'class' => ProcessorRewriteClasses::class,
            'config' => [
                DataManagerInterface::class => ['class' => DataManager::class],
            ],
        ],
        ProcessorGenerateFactories::ID => [
            'sort' => 200,
            'class' => ProcessorGenerateFactories::class,
            'config' => ['directory' => '/tmp/qunity/generated'],
        ],
        ProcessorCollectArguments::ID => [
            'sort' => 300,
            'class' => ProcessorCollectArguments::class,
        ],
    ])
    
  2. Request the required object:

    DependencyInjection::getInstance()->getObject(DataManagerInterface::class)
    

The processors have a specific role to play. It is possible to add, sort or disable processors.

  • processor RewriteClasses - allows you to override classes

    [<alias_class> => ['class' => <class>, 'enabled' => <bool>], ...]
    
  • processor GenerateFactories - allows you to automatically generate factories, to do this, add the "Factory" suffix to the required class

    ['directory' => <generated_code_directory>]
    
  • processor CollectArguments - collects the values of constructor arguments

    [<class> => [<arg> => <value>, ...], ...]