Skip to content

Commit

Permalink
[symfony#2322] Tweaks to new DI parameters component doc, including a…
Browse files Browse the repository at this point in the history
…dding links to areas where things were removed
  • Loading branch information
weaverryan committed Mar 30, 2013
1 parent 898eac7 commit b88d588
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
10 changes: 10 additions & 0 deletions book/service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ container and customizing objects from any third-party bundle. You'll begin
writing code that is more reusable, testable and decoupled, simply because
the service container makes writing good code so easy.

.. tip::

If you want to know a lot more after reading this chapter, check out
the :doc:`Dependency Injection Component Documentation</components/dependency_injection/introduction>`.

.. index::
single: Service Container; What is a service?

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

Array Parameters
~~~~~~~~~~~~~~~~

Parameters can also contain array values. See :ref:`component-di-parameters-array`.

Importing other Container Configuration Resources
-------------------------------------------------

Expand Down
32 changes: 18 additions & 14 deletions components/dependency_injection/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
single: Dependency Injection; Parameters

Introduction to Parameters
=================================
==========================

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

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

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

You can retrieve parameters set in the container with::
You can retrieve a parameter set in the container with::

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

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

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

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

.. configuration-block::

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

You can also use the parameters in the service definition, for example,
making the class of a service a parameter:
Expand Down Expand Up @@ -164,6 +164,8 @@ making the class of a service a parameter:
->addArgument('http://symfony.com/?foo=%%s&bar=%%d');
.. _component-di-parameters-array:

Array Parameters
----------------

Expand Down Expand Up @@ -221,6 +223,8 @@ arrays.
'fr' => array('fr', 'en'),
));
.. _component-di-parameters-constants:

Constants as Parameters
-----------------------

Expand Down
1 change: 1 addition & 0 deletions components/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

* :doc:`/components/dependency_injection/introduction`
* :doc:`/components/dependency_injection/types`
* :doc:`/components/dependency_injection/parameter`
* :doc:`/components/dependency_injection/definitions`
* :doc:`/components/dependency_injection/compilation`
* :doc:`/components/dependency_injection/tags`
Expand Down
6 changes: 6 additions & 0 deletions cookbook/configuration/external_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ You can now reference these parameters wherever you need them.
)
));
Constants
---------

The container also has support for setting PHP constants as parameters.
See :ref:`component-di-parameters-constants` for more details.

Miscellaneous Configuration
---------------------------

Expand Down

0 comments on commit b88d588

Please sign in to comment.