4xxi / strategy-injector
此包已被弃用且不再维护。未建议替代包。
Symfony 助手,用于实现“策略”模式
1.0.1
2020-01-31 10:24 UTC
Requires
- php: ^7.1.3
- symfony/config: ^4.0
- symfony/dependency-injection: ^4.0
- symfony/http-kernel: ^4.0
This package is auto-updated.
Last update: 2023-07-29 02:05:59 UTC
README
安装
- 通过 composer 安装组件
composer require 4xxi/strategy-injector
- 将以下配置内容添加到
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 #
使用方法
- 通过构造函数配置进行注入示例(这会将声明左侧实现接口的所有类注入到复合类中)
strategy_injector: App\Strategy\FooStrategyInterface: App\Strategy\CompositeFooStrategy
- 通过方法进行注入
strategy_injector: App\Strategy\FooStrategyInterface: method: 'addStrategy' class: App\Strategy\CompositeFooStrategy