- Install component via composer
composer require 4xxi/strategy-injector
- Add configuration yaml into
config/packages/strategy_injector.yaml
with following content:
strategy_injector:
# For using strategy injector via constructor:
# App\Interface: App\CompositeClass
# For using strategy injector via method call:
# App\Interface:
# method: 'addStrategy'
# class: App\CompositeClass
#
- Inject via constructor configuration example (that's injects all classes which implements interface on left side of declaration into composite class)
strategy_injector:
App\Strategy\FooStrategyInterface: App\Strategy\CompositeFooStrategy
- Inject via method
strategy_injector:
App\Strategy\FooStrategyInterface:
method: 'addStrategy'
class: App\Strategy\CompositeFooStrategy