This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection
Fabien Potencier d6b9011ebf feature #36373 [DI] add syntax to stack decorators (nicolas-grekas)
This PR was merged into the 5.1-dev branch.

Discussion
----------

[DI] add syntax to stack decorators

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #30599
| License       | MIT
| Doc PR        | -

Declare this:
```yaml
services:
    my_stack_of_decorators:
        stack:
            - class: App\ExternalDecorator
            - class: App\InternalDecorator
            - class: App\DecoratoredClass
```

And get this:
![image](https://user-images.githubusercontent.com/243674/78615803-b8c8e580-7872-11ea-95c2-22cb78f88ca8.png)

The PR is now ready with support for Yaml, XML and the PHP-DSL. It needs #36388, #36392 and #36389 to pass, and relates to #36390 to be DX-friendly.

The new syntax now supports composable stacks - i.e stack you can reuse in the middle of another stack.

RIP middleware, simple decorators FTW :)

From the test cases:
```yaml
services:
    reusable_stack:
        stack:
            - class: stdClass
              properties:
                  label: A
                  inner: '@.inner'
            - class: stdClass
              properties:
                  label: B
                  inner: '@.inner'

    concrete_stack:
        stack:
            - parent: reusable_stack
            - class: stdClass
              properties:
                  label: C
```

This will create a service similar to:
```php
(object) [
    'label' => 'A',
    'inner' => (object) [
        'label' => 'B',
        'inner' => (object) [
             'label' => 'C',
        ]
    ],
];
```

When used together with autowiring, this is enough to declare a stack of decorators:
```yaml
services:
    my_processing_stack:
        stack:
            - App\ExternalDecorator: ~
            - App\InternalDecorator: ~
            - App\TheDecoratedClass: ~
```

See fixtures for the other configuration formats.

See also https://twitter.com/nicolasgrekas/status/1248198573998604288

Todo:
- [x] rebase on top of #36388, #36392 and #36389 once they are merged
- [x] test declaring deeper nested stacks

Commits
-------

98eeeae3d1 [DI] add syntax to stack decorators
2020-04-24 11:12:12 +02:00
..
Argument [DI] fix definition and usage of AbstractArgument 2020-04-23 22:40:01 +02:00
Compiler feature #36373 [DI] add syntax to stack decorators (nicolas-grekas) 2020-04-24 11:12:12 +02:00
Config [Config] finish adding parameter types 2019-06-30 00:48:28 +02:00
Dumper [DI] fix definition and usage of AbstractArgument 2020-04-23 22:40:01 +02:00
Exception Allow \Throwable $previous everywhere 2019-11-12 15:51:11 +01:00
Extension Merge branch '4.4' into 5.0 2020-02-04 10:41:09 +01:00
LazyProxy Merge branch '4.4' 2019-08-20 18:53:57 +02:00
Loader feature #36373 [DI] add syntax to stack decorators (nicolas-grekas) 2020-04-24 11:12:12 +02:00
ParameterBag Leverage PHP8's get_debug_type() 2020-03-16 17:46:21 +01:00
Tests feature #36373 [DI] add syntax to stack decorators (nicolas-grekas) 2020-04-24 11:12:12 +02:00
.gitattributes add missing gitattributes for phpunit-bridge 2020-03-27 17:54:36 +01:00
.gitignore
Alias.php [DependencyInjection] improve the deprecation features by handling package+version info 2020-03-31 21:51:49 +02:00
CHANGELOG.md [DI] remove restriction and allow mixing "parent" and instanceof-conditionals/defaults/bindings 2020-04-12 09:10:44 +02:00
ChildDefinition.php [DI] remove restriction and allow mixing "parent" and instanceof-conditionals/defaults/bindings 2020-04-12 09:10:44 +02:00
composer.json Leverage PHP8's get_debug_type() 2020-03-16 17:46:21 +01:00
Container.php Merge branch '4.4' into 5.0 2020-03-18 09:00:37 +01:00
ContainerAwareInterface.php [HttpKernel] Fix inheritdocs 2018-08-29 14:45:36 +02:00
ContainerAwareTrait.php
ContainerBuilder.php [DI] fix definition and usage of AbstractArgument 2020-04-23 22:40:01 +02:00
ContainerInterface.php Merge branch '4.4' 2019-08-14 13:06:01 +02:00
Definition.php [DependencyInjection] improve the deprecation features by handling package+version info 2020-03-31 21:51:49 +02:00
EnvVarLoaderInterface.php [DI][FrameworkBundle] add EnvVarLoaderInterface - remove SecretEnvVarProcessor 2019-11-08 15:47:02 +01:00
EnvVarProcessor.php Use is_file() instead of file_exists() where possible 2020-04-24 00:29:19 +02:00
EnvVarProcessorInterface.php [DependencyInjection] Add type-hints to interfaces and implementations. 2019-07-06 20:02:14 +02:00
ExpressionLanguage.php [DI] cascade preloading only to public parameters/properties 2019-09-10 19:54:02 +02:00
ExpressionLanguageProvider.php switched array() to [] 2019-01-16 10:39:14 +01:00
LICENSE Update year in license files 2020-01-01 12:03:25 +01:00
Parameter.php
phpunit.xml.dist Bump phpunit XSD version to 5.2 2018-11-11 12:18:13 +01:00
README.md Update links to documentation 2020-01-04 13:05:51 +01:00
Reference.php
ReverseContainer.php [DependencyInjection] Add type-hints to interfaces and implementations. 2019-07-06 20:02:14 +02:00
ServiceLocator.php Last cleanups before beta 2019-11-12 12:24:05 +01:00
TaggedContainerInterface.php [DependencyInjection] Add type-hints to interfaces and implementations. 2019-07-06 20:02:14 +02:00
TypedReference.php [DI] Clarified deprecation for TypedReference in 4.4 2020-02-29 10:50:04 +01:00
Variable.php Add missing return annotations on magic methods 2019-08-23 10:37:16 +02:00

DependencyInjection Component

The DependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.

Resources