Skip to content

Commit aaa4a1c

Browse files
committed
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
2 parents 540d657 + 371e6dc commit aaa4a1c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class UnusedTagsPass implements CompilerPassInterface
3838
'container.service_locator',
3939
'container.service_locator_context',
4040
'container.service_subscriber',
41+
'container.stack',
4142
'controller.argument_value_resolver',
4243
'controller.service_arguments',
4344
'data_collector',

0 commit comments

Comments
 (0)