4xxi/strategy-injector

此包已被弃用且不再维护。未建议替代包。

Symfony 助手,用于实现“策略”模式

安装: 742

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 4

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.1 2020-01-31 10:24 UTC

This package is auto-updated.

Last update: 2023-07-29 02:05:59 UTC


README

安装

  1. 通过 composer 安装组件
composer require 4xxi/strategy-injector
  1. 将以下配置内容添加到 config/packages/strategy_injector.yaml
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
    #

使用方法

  1. 通过构造函数配置进行注入示例(这会将声明左侧实现接口的所有类注入到复合类中)
strategy_injector:
    App\Strategy\FooStrategyInterface: App\Strategy\CompositeFooStrategy
  1. 通过方法进行注入
strategy_injector:
    App\Strategy\FooStrategyInterface:
        method: 'addStrategy'
        class: App\Strategy\CompositeFooStrategy