lilinen/decor-bundle

Symfony bundle for LiLinen/Decor library

Installs: 15

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

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

This package is auto-updated.

Last update: 2024-04-29 00:08:09 UTC


README

Build Status

Symfony bundle for LiLinen/Decor library

Installation

composer require lilinen/decor-bundle

Register the bundle:

<?php
// config/bundles.php

return [
    // ...
    LiLinen\DecorBundle\LiLinenDecorBundle::class => ['all' => true],
];

Usage

Decorating a service

<?php
// src/Service/MyService.php

namespace App\Service;

use App\My\Annotions\MyCustomAnnotation;

class MyService
{
    /**
     * @MyCustomAnnotation 
     */
    public function foo()
    {
        // ...
    }
}

To automatically decorate the service with the decorated tag:

# config/services.yml
services:
    App\Service\MyService:
        tags:
            - { name: decorated }

Alternatively, the factory can be registered manually:

# 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'

Registering a decorator service

Services with the lilinen_decor.decorator tag are automatically registered. See DecoratorPass for implementation details.

For example, if you have a custom Decorator:

<?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 }

Related Projects