Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/internations/decoratorbundle
Provides consistent decorator handling for the Symfony2 Dependency Injection Container
https://github.com/internations/decoratorbundle
Last synced: 9 days ago
JSON representation
Provides consistent decorator handling for the Symfony2 Dependency Injection Container
- Host: GitHub
- URL: https://github.com/internations/decoratorbundle
- Owner: InterNations
- Created: 2014-03-21T05:15:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-07-30T11:54:30.000Z (4 months ago)
- Last Synced: 2024-11-07T04:11:39.497Z (12 days ago)
- Language: PHP
- Size: 31.3 KB
- Stars: 3
- Watchers: 33
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DecoratorBundle for Symfony
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/InterNations/DecoratorBundle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/InterNations/DecoratorBundle.svg?branch=master)](https://travis-ci.org/InterNations/DecoratorBundle) [![Dependency Status](https://www.versioneye.com/user/projects/53479c66fe0d0720b500007c/badge.png)](https://www.versioneye.com/user/projects/53479c66fe0d0720b500007c) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/InterNations/DecoratorBundle.svg)](http://isitmaintained.com/project/InterNations/DecoratorBundle "Average time to resolve an issue") [![Percentage of issues still open](http://isitmaintained.com/badge/open/InterNations/DecoratorBundle.svg)](http://isitmaintained.com/project/InterNations/DecoratorBundle "Percentage of issues still open")Provides consistent decorator handling for the Symfony Dependency Injection Container.
## Installation
For Symfony 3.3 up to 4:
```bash
composer require internations/decorator-bundle
```For Symfony < 3.3:
```bash
composer require internations/decorator-bundle:~0
```## Usage
### "Decorate this"-mode
In "decorate this"-mode you declare your decorators in the dependency at hand. A configuration example:
```xml
element1
element2
```
The configuration above will create this instance:
```php
$iterator = new InfiniteIterator(
new ArrayIterator(['element1', 'element2'])
);
```### "Decorate other" mode
In "decorate other"-mode you declare the subjects you are decorating in the decorator definition itself. A configuration
example:```xml
element1
element2
```
The configuration above will again create this instance:
```php
$iterator = new InfiniteIterator(
new ArrayIterator(['element1', 'element2'])
);
```### Specifying priorities
To control the order of decoration, setting a priority flag for the decorator is supported. Priority can be between
`PHP_INT_MAX` and `-PHP_INT_MAX`, the default priority is `0`.```xml
```
### Using the Bundle programmatically
In cases where you want to reuse the decoration functionality outside of the XML config, you can use the following API
in your Compiler Pass. Here is an example to add decorate service `common_service` with the decorator
`special_decorator` and priority `255`.```php
namespace …;use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use InterNations\Bundle\DecoratorBundle\Tagger\DecorationTagger;
use Symfony\Component\DependencyInjection\ContainerBuilder;class MyCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
DecorationTagger::tag($container, 'common_service', 'special_decorator', 255);
}
}
```## Credits
Based on Dovydas Bartkevicius’ idea, with a bunch of input from Max Beutel.