Skip to content

Commit b88d588

Browse files
committed
[#2322] Tweaks to new DI parameters component doc, including adding links to areas where things were removed
1 parent 898eac7 commit b88d588

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

book/service_container.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ container and customizing objects from any third-party bundle. You'll begin
2828
writing code that is more reusable, testable and decoupled, simply because
2929
the service container makes writing good code so easy.
3030

31+
.. tip::
32+
33+
If you want to know a lot more after reading this chapter, check out
34+
the :doc:`Dependency Injection Component Documentation</components/dependency_injection/introduction>`.
35+
3136
.. index::
3237
single: Service Container; What is a service?
3338

@@ -239,6 +244,11 @@ third-party bundles will *always* use parameters as they make the service
239244
stored in the container more configurable. For the services in your application,
240245
however, you may not need the flexibility of parameters.
241246

247+
Array Parameters
248+
~~~~~~~~~~~~~~~~
249+
250+
Parameters can also contain array values. See :ref:`component-di-parameters-array`.
251+
242252
Importing other Container Configuration Resources
243253
-------------------------------------------------
244254

components/dependency_injection/parameters.rst

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
single: Dependency Injection; Parameters
33

44
Introduction to Parameters
5-
=================================
5+
==========================
66

77
You can define parameters in the service container which can then be used
88
directly or as part of service definitions. This can help to separate out
@@ -11,13 +11,13 @@ values that you will want to change more regularly.
1111
Getting and Setting Container Parameters
1212
----------------------------------------
1313

14-
Working with container parameters is straight forward using the container's
14+
Working with container parameters is straightforward using the container's
1515
accessor methods for parameters. You can check if a parameter has been defined
1616
in the container with::
1717

1818
$container->hasParameter('mailer.transport');
1919

20-
You can retrieve parameters set in the container with::
20+
You can retrieve a parameter set in the container with::
2121

2222
$container->getParameter('mailer.transport');
2323

@@ -29,7 +29,7 @@ and set a parameter in the container with::
2929

3030
You can only set a parameter before the container is compiled. To learn
3131
more about compiling the container see
32-
:doc:`/components/dependency_injection/compilation`
32+
:doc:`/components/dependency_injection/compilation`.
3333

3434
Parameters in Configuration Files
3535
---------------------------------
@@ -54,14 +54,14 @@ You can also use the ``parameters`` section of a config file to set parameters:
5454
$container->setParameter('mailer.transport', 'sendmail');
5555
5656
As well as retrieving the parameter values directly from the container you
57-
can use them in the config files. You can refer to parameters elsewhere in
58-
the config files by surrounding them with percent (``%``) signs, e.g.
59-
``%mailer.transport%``. One use is for this is to inject the values into your
60-
services. This allows you to configure different versions of services between
61-
applications or multiple services based on the same class but configured
62-
differently within a single application. You could inject the choice of mail
63-
transport into the ``Mailer`` class directly but by making it a parameter it
64-
makes it easier to change rather than being tied up with the service definition:
57+
can use them in the config files. You can refer to parameters elsewhere by
58+
surrounding them with percent (``%``) signs, e.g. ``%mailer.transport%``.
59+
One use for this is to inject the values into your services. This allows
60+
you to configure different versions of services between applications or multiple
61+
services based on the same class but configured differently within a single
62+
application. You could inject the choice of mail transport into the ``Mailer``
63+
class directly but by making it a parameter. This makes it easier to change
64+
rather than being tied up and hidden with the service definition:
6565

6666
.. configuration-block::
6767

@@ -97,8 +97,8 @@ makes it easier to change rather than being tied up with the service definition:
9797
->register('mailer', 'Mailer')
9898
->addArgument('%mailer.transport%');
9999
100-
If we were using this elsewhere as well, then it would only need changing
101-
in one place if a different transport was required.
100+
If you were using this elsewhere as well, then you would only need to change
101+
the parameter value in one place if needed.
102102

103103
You can also use the parameters in the service definition, for example,
104104
making the class of a service a parameter:
@@ -164,6 +164,8 @@ making the class of a service a parameter:
164164
165165
->addArgument('http://symfony.com/?foo=%%s&bar=%%d');
166166
167+
.. _component-di-parameters-array:
168+
167169
Array Parameters
168170
----------------
169171

@@ -221,6 +223,8 @@ arrays.
221223
'fr' => array('fr', 'en'),
222224
));
223225
226+
.. _component-di-parameters-constants:
227+
224228
Constants as Parameters
225229
-----------------------
226230

components/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
* :doc:`/components/dependency_injection/introduction`
2828
* :doc:`/components/dependency_injection/types`
29+
* :doc:`/components/dependency_injection/parameter`
2930
* :doc:`/components/dependency_injection/definitions`
3031
* :doc:`/components/dependency_injection/compilation`
3132
* :doc:`/components/dependency_injection/tags`

cookbook/configuration/external_parameters.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ You can now reference these parameters wherever you need them.
9494
)
9595
));
9696
97+
Constants
98+
---------
99+
100+
The container also has support for setting PHP constants as parameters.
101+
See :ref:`component-di-parameters-constants` for more details.
102+
97103
Miscellaneous Configuration
98104
---------------------------
99105

0 commit comments

Comments
 (0)