Skip to content

Commit 1d0f1a1

Browse files
Changing uses of we to you in the service container book chapter
1 parent 3607bdf commit 1d0f1a1

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

book/service_container.rst

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ your product inventory, or another object that processes data from a third-party
1212
API. The point is that a modern application does many things and is organized
1313
into many objects that handle each task.
1414

15-
In this chapter, we'll talk about a special PHP object in Symfony2 that helps
15+
This chapter is about a special PHP object in Symfony2 that helps
1616
you instantiate, organize and retrieve the many objects of your application.
1717
This object, called a service container, will allow you to standardize and
1818
centralize the way objects are constructed in your application. The container
1919
makes your life easier, is super fast, and emphasizes an architecture that
20-
promotes reusable and decoupled code. And since all core Symfony2 classes
20+
promotes reusable and decoupled code. Since all core Symfony2 classes
2121
use the container, you'll learn how to extend, configure and use any object
2222
in Symfony2. In large part, the service container is the biggest contributor
2323
to the speed and extensibility of Symfony2.
@@ -69,9 +69,9 @@ What is a Service Container?
6969

7070
A :term:`Service Container` (or *dependency injection container*) is simply
7171
a PHP object that manages the instantiation of services (i.e. objects).
72-
For example, suppose we have a simple PHP class that delivers email messages.
73-
Without a service container, we must manually create the object whenever
74-
we need it:
72+
For example, suppose you have a simple PHP class that delivers email messages.
73+
Without a service container, you must manually create the object whenever
74+
you need it:
7575

7676
.. code-block:: php
7777
@@ -82,11 +82,11 @@ we need it:
8282
8383
This is easy enough. The imaginary ``Mailer`` class allows us to configure
8484
the method used to deliver the email messages (e.g. ``sendmail``, ``smtp``, etc).
85-
But what if we wanted to use the mailer service somewhere else? We certainly
86-
don't want to repeat the mailer configuration *every* time we need to use
87-
the ``Mailer`` object. What if we needed to change the ``transport`` from
88-
``sendmail`` to ``smtp`` everywhere in the application? We'd need to hunt
89-
down every place we create a ``Mailer`` service and change it.
85+
But what if you wanted to use the mailer service somewhere else? You certainly
86+
don't want to repeat the mailer configuration *every* time you need to use
87+
the ``Mailer`` object. What if you needed to change the ``transport`` from
88+
``sendmail`` to ``smtp`` everywhere in the application? You'd need to hunt
89+
down every place you create a ``Mailer`` service and change it.
9090

9191
.. index::
9292
single: Service Container; Configuring services
@@ -95,7 +95,7 @@ Creating/Configuring Services in the Container
9595
----------------------------------------------
9696

9797
A better answer is to let the service container create the ``Mailer`` object
98-
for you. In order for this to work, we must *teach* the container how to
98+
for you. In order for this to work, you must *teach* the container how to
9999
create the ``Mailer`` service. This is done via configuration, which can
100100
be specified in YAML, XML or PHP:
101101

@@ -154,7 +154,7 @@ shortcut method::
154154
}
155155
}
156156

157-
When we ask for the ``my_mailer`` service from the container, the container
157+
When you ask for the ``my_mailer`` service from the container, the container
158158
constructs the object and returns it. This is another major advantage of
159159
using the service container. Namely, a service is *never* constructed until
160160
it's needed. If you define a service and never use it on a request, the service
@@ -164,7 +164,7 @@ lots of services. Services that are never used are never constructed.
164164

165165
As an added bonus, the ``Mailer`` service is only created once and the same
166166
instance is returned each time you ask for the service. This is almost always
167-
the behavior you'll need (it's more flexible and powerful), but we'll learn
167+
the behavior you'll need (it's more flexible and powerful), but you'll learn
168168
later how you can configure a service that has multiple instances.
169169

170170
.. _book-service-container-parameters:
@@ -217,16 +217,16 @@ straightforward. Parameters make defining services more organized and flexible:
217217
));
218218
219219
The end result is exactly the same as before - the difference is only in
220-
*how* we defined the service. By surrounding the ``my_mailer.class`` and
220+
*how* you defined the service. By surrounding the ``my_mailer.class`` and
221221
``my_mailer.transport`` strings in percent (``%``) signs, the container knows
222222
to look for parameters with those names. When the container is built, it
223223
looks up the value of each parameter and uses it in the service definition.
224224

225225
.. note::
226226

227-
The percent sign inside a parameter or argument, as part of the string, must
227+
The percent sign inside a parameter or argument, as part of the string, must
228228
be escaped with another percent sign:
229-
229+
230230
.. code-block:: xml
231231
232232
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
@@ -240,7 +240,7 @@ Parameters, however, have several advantages:
240240

241241
* parameter values can be used in multiple service definitions;
242242

243-
* when creating a service in a bundle (we'll show this shortly), using parameters
243+
* when creating a service in a bundle (this follows shortly), using parameters
244244
allows the service to be easily customized in your application.
245245

246246
The choice of using or not using parameters is up to you. High-quality
@@ -311,7 +311,7 @@ Importing other Container Configuration Resources
311311

312312
.. tip::
313313

314-
In this section, we'll refer to service configuration files as *resources*.
314+
In this section, service configuration files are referred to as *resources*.
315315
This is to highlight that fact that, while most configuration resources
316316
will be files (e.g. YAML, XML, PHP), Symfony2 is so flexible that configuration
317317
could be loaded from anywhere (e.g. a database or even via an external
@@ -323,9 +323,9 @@ The service container is built using a single configuration resource
323323
be imported from inside this file in one way or another. This gives you absolute
324324
flexibility over the services in your application.
325325

326-
External service configuration can be imported in two different ways. First,
327-
we'll talk about the method that you'll use most commonly in your application:
328-
the ``imports`` directive. In the following section, we'll introduce the
326+
External service configuration can be imported in two different ways. First up is
327+
the method that you'll use most commonly in your application:
328+
the ``imports`` directive. The section after introduces the
329329
second method, which is the flexible and preferred method for importing service
330330
configuration from third-party bundles.
331331

@@ -337,7 +337,7 @@ configuration from third-party bundles.
337337
Importing Configuration with ``imports``
338338
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
339339

340-
So far, we've placed our ``my_mailer`` service container definition directly
340+
So far, you've placed our ``my_mailer`` service container definition directly
341341
in the application configuration file (e.g. ``app/config/config.yml``). Of
342342
course, since the ``Mailer`` class itself lives inside the ``AcmeHelloBundle``,
343343
it makes more sense to put the ``my_mailer`` container definition inside the
@@ -389,7 +389,7 @@ directories don't exist, create them.
389389
));
390390
391391
The definition itself hasn't changed, only its location. Of course the service
392-
container doesn't know about the new resource file. Fortunately, we can
392+
container doesn't know about the new resource file. Fortunately, you can
393393
easily import the resource file using the ``imports`` key in the application
394394
configuration.
395395

@@ -436,7 +436,7 @@ Symfony2 core services, are usually loaded using another method that's more
436436
flexible and easy to configure in your application.
437437

438438
Here's how it works. Internally, each bundle defines its services very much
439-
like we've seen so far. Namely, a bundle uses one or more configuration
439+
like you've seen so far. Namely, a bundle uses one or more configuration
440440
resource files (usually XML) to specify the parameters and services for that
441441
bundle. However, instead of importing each of these resources directly from
442442
your application configuration using the ``imports`` directive, you can simply
@@ -452,7 +452,7 @@ to accomplish two things:
452452
service container configuration.
453453

454454
In other words, a service container extension configures the services for
455-
a bundle on your behalf. And as we'll see in a moment, the extension provides
455+
a bundle on your behalf. And as you'll see in a moment, the extension provides
456456
a sensible, high-level interface for configuring the bundle.
457457

458458
Take the ``FrameworkBundle`` - the core Symfony2 framework bundle - as an
@@ -541,10 +541,10 @@ in its constructor, which is easily configurable. As you'll see, the real
541541
power of the container is realized when you need to create a service that
542542
depends on one or more other services in the container.
543543

544-
Let's start with an example. Suppose we have a new service, ``NewsletterManager``,
544+
Let's start with an example. Suppose you have a new service, ``NewsletterManager``,
545545
that helps to manage the preparation and delivery of an email message to
546546
a collection of addresses. Of course the ``my_mailer`` service is already
547-
really good at delivering email messages, so we'll use it inside ``NewsletterManager``
547+
really good at delivering email messages, so you'll use it inside ``NewsletterManager``
548548
to handle the actual delivery of the messages. This pretend class might look
549549
something like this::
550550

@@ -565,7 +565,7 @@ something like this::
565565
// ...
566566
}
567567

568-
Without using the service container, we can create a new ``NewsletterManager``
568+
Without using the service container, you can create a new ``NewsletterManager``
569569
fairly easily from inside a controller::
570570

571571
public function sendNewsletterAction()
@@ -575,8 +575,8 @@ fairly easily from inside a controller::
575575
// ...
576576
}
577577

578-
This approach is fine, but what if we decide later that the ``NewsletterManager``
579-
class needs a second or third constructor argument? What if we decide to
578+
This approach is fine, but what if you decide later that the ``NewsletterManager``
579+
class needs a second or third constructor argument? What if you decide to
580580
refactor our code and rename the class? In both cases, you'd need to find every
581581
place where the ``NewsletterManager`` is instantiated and modify it. Of course,
582582
the service container gives us a much more appealing option:
@@ -812,7 +812,7 @@ In Symfony2, you'll constantly use services provided by the Symfony core or
812812
other third-party bundles to perform tasks such as rendering templates (``templating``),
813813
sending emails (``mailer``), or accessing information on the request (``request``).
814814

815-
We can take this a step further by using these services inside services that
815+
You can take this a step further by using these services inside services that
816816
you've created for your application. Let's modify the ``NewsletterManager``
817817
to use the real Symfony2 ``mailer`` service (instead of the pretend ``my_mailer``).
818818
Let's also pass the templating engine service to the ``NewsletterManager``
@@ -873,7 +873,7 @@ the framework.
873873
.. tip::
874874

875875
Be sure that ``swiftmailer`` entry appears in your application
876-
configuration. As we mentioned in :ref:`service-container-extension-configuration`,
876+
configuration. As you mentioned in :ref:`service-container-extension-configuration`,
877877
the ``swiftmailer`` key invokes the service extension from the
878878
``SwiftmailerBundle``, which registers the ``mailer`` service.
879879

0 commit comments

Comments
 (0)