File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ Dependency Injection
4343* :ref: `TaggedLocator <service-subscribers-locators_defining-service-locator >`
4444* :ref: `Target <autowiring-multiple-implementations-same-type >`
4545* :ref: `When <service-container_limiting-to-env >`
46+ * :ref: `WhenNot <service-container_limiting-to-env >`
4647
4748EventDispatcher
4849~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -260,6 +260,32 @@ as a service in some environments::
260260 // ...
261261 }
262262
263+ If you want to exclude a service from being registered in a specific
264+ environment, you can use the ``#[WhenNot] `` attribute::
265+
266+ use Symfony\Component\DependencyInjection\Attribute\WhenNot;
267+
268+ // SomeClass is registered in all environments except "dev"
269+
270+ #[WhenNot(env: 'dev')]
271+ class SomeClass
272+ {
273+ // ...
274+ }
275+
276+ // you can apply more than one WhenNot attribute to the same class
277+
278+ #[WhenNot(env: 'dev')]
279+ #[WhenNot(env: 'test')]
280+ class AnotherClass
281+ {
282+ // ...
283+ }
284+
285+ .. versionadded :: 7.2
286+
287+ The ``#[WhenNot] `` attribute was introduced in Symfony 7.2.
288+
263289.. _services-constructor-injection :
264290
265291Injecting Services/Config into a Service
You can’t perform that action at this time.
0 commit comments