@@ -93,13 +93,14 @@ Then, register the class as a service that :doc:`decorates </service_container/s
93
93
.. code-block :: yaml
94
94
95
95
# config/services.yaml
96
- services :
97
- App\CacheKernel :
98
- decorates : http_cache
99
- arguments :
100
- - ' @kernel'
101
- - ' @http_cache.store'
102
- - ' @?esi'
96
+ when@prod :
97
+ services :
98
+ App\CacheKernel :
99
+ decorates : http_cache
100
+ arguments :
101
+ - ' @kernel'
102
+ - ' @http_cache.store'
103
+ - ' @?esi'
103
104
104
105
.. code-block :: xml
105
106
@@ -110,11 +111,15 @@ Then, register the class as a service that :doc:`decorates </service_container/s
110
111
xsi : schemaLocation =" http://symfony.com/schema/dic/services
111
112
https://symfony.com/schema/dic/services/services-1.0.xsd"
112
113
>
113
- <service id =" App\CacheKernel" decorates =" http_cache" >
114
- <argument type =" service" id =" kernel" />
115
- <argument type =" service" id =" http_cache.store" />
116
- <argument type =" service" id =" esi" on-invalid =" null" />
117
- </service >
114
+ <when env =" prod" >
115
+ <services >
116
+ <service id =" App\CacheKernel" decorates =" http_cache" >
117
+ <argument type =" service" id =" kernel" />
118
+ <argument type =" service" id =" http_cache.store" />
119
+ <argument type =" service" id =" esi" on-invalid =" null" />
120
+ </service >
121
+ </services >
122
+ </when >
118
123
</container >
119
124
120
125
.. code-block :: php
@@ -124,17 +129,18 @@ Then, register the class as a service that :doc:`decorates </service_container/s
124
129
125
130
use App\CacheKernel;
126
131
127
- return function (ContainerConfigurator $containerConfigurator) {
128
- $services = $containerConfigurator->services();
129
-
130
- $services->set(CacheKernel::class)
131
- ->decorate('http_cache')
132
- ->args([
133
- service('kernel'),
134
- service('http_cache.store'),
135
- service('esi')->nullOnInvalid(),
136
- ])
137
- ;
132
+ return function (ContainerConfigurator $containerConfigurator, string $env) {
133
+ if ('prod' === $env) {
134
+ $containerConfigurator->services()
135
+ ->set(CacheKernel::class)
136
+ ->decorate('http_cache')
137
+ ->args([
138
+ service('kernel'),
139
+ service('http_cache.store'),
140
+ service('esi')->nullOnInvalid(),
141
+ ])
142
+ ;
143
+ }
138
144
};
139
145
140
146
.. caution ::
0 commit comments