Skip to content

Commit fd9b155

Browse files
committed
Tweaks
1 parent 7fa3cca commit fd9b155

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

components/dependency_injection.rst

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ like this::
170170

171171
$newsletterManager = $containerBuilder->get('newsletter_manager');
172172

173-
Behavior When Service Does Not Exist
174-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173+
Getting Services That Don't Exist
174+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175175

176-
By default, an exception is throw when a service does not exist. You can override the behavior by::
176+
By default, when you try to get a service that doesn't exist, you see an exception.
177+
You can override this behavior as follows::
177178

178179
use Symfony\Component\DependencyInjection\ContainerBuilder;
179180
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -182,17 +183,22 @@ By default, an exception is throw when a service does not exist. You can overrid
182183

183184
// ...
184185

185-
// the second argument is optional and define the behavior
186+
// the second argument is optional and defines what to do when the service doesn't exist
186187
$newsletterManager = $containerBuilder->get('newsletter_manager', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
187188

188189

189-
Possible behaviors are:
190+
These are all the possible behaviors:
190191

191-
* ``ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE``: Throws an exception at compile time **default**
192-
* ``ContainerInterface::NULL_ON_INVALID_REFERENCE``: Returns null
193-
* ``ContainerInterface::IGNORE_ON_INVALID_REFERENCE``: Ignores the wrapping command asking for the reference (for instance, ignore a setter if the service does not exist)
194-
* ``ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE``: Ignores/returns null for uninitialized services or invalid references
195-
* ``ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE``: Throws an exception at runtime, when trying to access the missing service
192+
* ``ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE``: throws an exception
193+
at compile time (this is the **default** behavior);
194+
* ``ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE``: throws an
195+
exception at runtime, when trying to access the missing service;
196+
* ``ContainerInterface::NULL_ON_INVALID_REFERENCE``: returns ``null``;
197+
* ``ContainerInterface::IGNORE_ON_INVALID_REFERENCE``: ignores the wrapping
198+
command asking for the reference (for instance, ignore a setter if the service
199+
does not exist);
200+
* ``ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE``: ignores/returns
201+
``null`` for uninitialized services or invalid references.
196202

197203
Avoiding your Code Becoming Dependent on the Container
198204
------------------------------------------------------

0 commit comments

Comments
 (0)