Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add note on service parameters regarding ScopeWideningInjectionException #2424

Merged
merged 4 commits into from

4 participants

@joelclermont
Q A
Doc fix? yes
New docs? yes
Applies to all
Fixed tickets #1707

Based on our discussion in IRC, instead of describing how to use strict=false, I linked to the cookbook article on Scopes for the recommended solutions.

book/service_container.rst
@@ -231,6 +231,15 @@ looks up the value of each parameter and uses it in the service definition.
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
+.. note::
+
+ It can be useful to pass other services in as arguments to your custom service.
+ For example, you may want to pass in the `request` service as an argument.
+ In these cases, you may receive a `ScopeWideningInjectionException`.
@WouterJ Collaborator
WouterJ added a note

you must use double backticks to indicate an inline code block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@joelclermont

Oops, so hard to shake my Markdown brain. Fixed.

book/service_container.rst
@@ -231,6 +231,15 @@ looks up the value of each parameter and uses it in the service definition.
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
+.. note::
+
+ It can be useful to pass other services in as arguments to your custom service.
+ For example, you may want to pass in the ``request`` service as an argument.
+ In these cases, you may receive a ``ScopeWideningInjectionException``.
+ To understand this problem better and learn how to solve it, refer to
+ the cookbook article :doc:`/cookbook/service_container/scopes` for a
+ few solutions.

I would delete "for a few solutions".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
book/service_container.rst
@@ -231,6 +231,14 @@ looks up the value of each parameter and uses it in the service definition.
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
+.. note::
@WouterJ Collaborator
WouterJ added a note

I think it should be a .. caution:: block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
book/service_container.rst
@@ -231,6 +231,14 @@ looks up the value of each parameter and uses it in the service definition.
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
+.. note::
+
+ It can be useful to pass other services in as arguments to your custom service.
@WouterJ Collaborator
WouterJ added a note

this sentence is not needed, as this article is telling about it. Because it's a caution block, I prefer to have something like:

You may receive a :class:`Symfony\\....\\ScopeWideningInjectionException` when
passing the ``request`` service as an argument. To understand this problem better
and leran how to solve it, refer to the ":doc:`/cookbook/service_container/scope`"

(please note that the api link for the exception class is not correct right now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weaverryan weaverryan merged commit 7b0bfac into symfony:2.0
@weaverryan
Collaborator

Hey Joel!

Nice work here - and good use of existing documentation.

Thanks!

@joelclermont joelclermont deleted the joelclermont:issue_1707 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 0 deletions.
  1. +8 −0 book/service_container.rst
View
8 book/service_container.rst
@@ -231,6 +231,14 @@ looks up the value of each parameter and uses it in the service definition.
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
+.. caution::
+
+ You may receive a
+ :class:`Symfony\\Component\\DependencyInjection\\Exception\\ScopeWideningInjectionException`
+ when passing the ``request`` service as an argument. To understand this
+ problem better and learn how to solve it, refer to the cookbook article
+ :doc:`/cookbook/service_container/scopes`.
+
The purpose of parameters is to feed information into services. Of course
there was nothing wrong with defining the service without using any parameters.
Parameters, however, have several advantages:
Something went wrong with that request. Please try again.