4xxi/strategy-injector

Symfony helper for implementing "Strategy" pattern

Installs: 658

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.0.1 2020-01-31 10:24 UTC

This package is auto-updated.

Last update: 2021-11-29 02:49:01 UTC


README

Installation

  1. Install component via composer
composer require 4xxi/strategy-injector
  1. 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
    #

Usage

  1. 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
  1. Inject via method
strategy_injector:
    App\Strategy\FooStrategyInterface:
        method: 'addStrategy'
        class: App\Strategy\CompositeFooStrategy