lilinen / decor-bundle
LiLinen/Decor 库的 Symfony 扩展包
dev-master
2018-11-28 12:01 UTC
Requires
- lilinen/decor: dev-master
- symfony/cache: ^4.1
- symfony/config: ^4.1
- symfony/dependency-injection: ^4.1
- symfony/http-kernel: ^4.1
- symfony/yaml: ^4.1
Requires (Dev)
- phpstan/phpstan: ^0.10.5
- phpunit/phpunit: ^7.4
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-09-29 01:08:55 UTC
README
LiLinen/Decor 库的 Symfony 扩展包
安装
composer require lilinen/decor-bundle
注册扩展包
<?php // config/bundles.php return [ // ... LiLinen\DecorBundle\LiLinenDecorBundle::class => ['all' => true], ];
使用
装饰服务
<?php // src/Service/MyService.php namespace App\Service; use App\My\Annotions\MyCustomAnnotation; class MyService { /** * @MyCustomAnnotation */ public function foo() { // ... } }
自动使用 decorated
标签装饰服务
# config/services.yml services: App\Service\MyService: tags: - { name: decorated }
或者,可以手动注册工厂
# config/services.yml services: App\Service\MyService: factory: 'app.decor.factory.my_service:create' app.decor.factory.my_service: parent: 'lilinen_decor.factory' autowire: true autoconfigure: false public: false arguments: $class: 'App\Service\MyService'
注册装饰服务
带有 lilinen_decor.decorator
标签的服务将自动注册。详见 DecoratorPass 的实现细节。
例如,如果你有一个自定义装饰器
<?php // src/Decorator/MyCustomDecorator.php namespace App\Decorator; use LiLinen\Decor\Decorator\DecoratorInterface class MyCustomDecorator implements DecoratorInterface { //... }
# config/services.yml services: App\My\Decorator\MyCustomDecorator: tags: - { name: lilinen_decor.decorator }