lilinen/decor-bundle

LiLinen/Decor 库的 Symfony 扩展包

安装: 15

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

公开问题: 0

类型:symfony-bundle

dev-master 2018-11-28 12:01 UTC

This package is auto-updated.

Last update: 2024-09-29 01:08:55 UTC


README

Build Status

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 }

相关项目