Skip to content

Commit 80a3643

Browse files
committed
some tweaks and fixes to d417f7b and 3dcbbc2
1 parent 941a5cc commit 80a3643

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

book/service_container.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,9 @@ Injecting the Request
763763
The ``request_stack`` service was introduced in version 2.4.
764764

765765
As of Symfony 2.4, instead of injecting the ``request`` service, you should
766-
inject the ``request_stack`` service instead and access the Request by calling
767-
the ``getCurrentRequest()`` method:
766+
inject the ``request_stack`` service and access the ``Request`` by calling
767+
the :method:`Symfony\\Component\\HttpFoundation\\RequestStack::getCurrentRequest`
768+
method::
768769

769770
namespace Acme\HelloBundle\Newsletter;
770771

@@ -830,7 +831,7 @@ Now, just inject the ``request_stack``, which behaves like any normal service:
830831
array(new Reference('request_stack'))
831832
));
832833
833-
.. sidebar: Why not Inject the request Service?
834+
.. sidebar:: Why not Inject the ``request`` Service?
834835

835836
Almost all Symfony2 built-in services behave in the same way: a single
836837
instance is created by the container which it returns whenever you get it or

cookbook/service_container/scopes.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ This entry is all about scopes, a somewhat advanced topic related to the
1212

1313
If you are trying to inject the ``request`` service, the simple solution
1414
is to inject the ``request_stack`` service instead and access the current
15-
Request by calling the ``getCurrentRequest()`` method (see :ref:`book-container-request-stack`).
16-
The rest of this entry talks about scopes in a theoretical and more advanced
17-
way. If you're dealing with scopes for the ``request`` service, simply
18-
inject ``request_stack``.
15+
Request by calling the
16+
:method:`Symfony\\Component\\HttpFoundation\\RequestStack::getCurrentRequest`
17+
method (see :ref:`book-container-request-stack`). The rest of this entry
18+
talks about scopes in a theoretical and more advanced way. If you're
19+
dealing with scopes for the ``request`` service, simply inject ``request_stack``.
1920

2021
Understanding Scopes
2122
--------------------
@@ -35,7 +36,7 @@ also defines a third scope: ``request``. This scope is tied to the request,
3536
meaning a new instance is created for each subrequest and is unavailable
3637
outside the request (for instance in the CLI).
3738

38-
An Example: client Scope
39+
An Example: Client Scope
3940
~~~~~~~~~~~~~~~~~~~~~~~~
4041

4142
Other than the ``request`` service (which has a simple solution, see the
@@ -92,13 +93,13 @@ when compiling the container. Read the sidebar below for more details.
9293
A service can of course depend on a service from a wider scope without
9394
any issue.
9495

95-
Using a Service from a narrower Scope
96+
Using a Service from a Narrower Scope
9697
-------------------------------------
9798

9899
There are several solutions to the scope problem:
99100

100-
* A) Use setter injection if the dependency is "synchronized"; (see
101-
:ref:`using-synchronized-service`).
101+
* A) Use setter injection if the dependency is ``synchronized`` (see
102+
:ref:`using-synchronized-service`);
102103

103104
* B) Put your service in the same scope as the dependency (or a narrower one). If
104105
you depend on the ``client_configuration`` service, this means putting your
@@ -107,13 +108,13 @@ There are several solutions to the scope problem:
107108
* C) Pass the entire container to your service and retrieve your dependency from
108109
the container each time you need it to be sure you have the right instance
109110
-- your service can live in the default ``container`` scope (see
110-
:ref:`passing-container`);
111+
:ref:`passing-container`).
111112

112113
Each scenario is detailed in the following sections.
113114

114115
.. _using-synchronized-service:
115116

116-
A) Using a synchronized Service
117+
A) Using a Synchronized Service
117118
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118119

119120
.. versionadded:: 2.3

0 commit comments

Comments
 (0)