Skip to content

Commit fc913c0

Browse files
committed
Documented all parameter types
1 parent 31443a3 commit fc913c0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

components/dependency_injection/parameters.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,67 @@ key, and define the type as ``constant``.
264264
# app/config/config.yml
265265
imports:
266266
- { resource: parameters.xml }
267+
268+
PHP keywords in XML
269+
-------------------
270+
271+
By default, ``true``, ``false`` and ``null`` in XML are converted to the PHP
272+
keywords (respectively ``true``, ``false`` and ``null``):
273+
274+
.. code-block:: xml
275+
276+
<parameters>
277+
<parameter key="mailer.send_all_in_once">false</parameters>
278+
</parameters>
279+
280+
<!-- after parsing
281+
$container->getParameter('mailer.send_all_in_once'); // returns false
282+
-->
283+
284+
To disable this behaviour, use the ``string`` type:
285+
286+
.. code-block:: xml
287+
288+
<parameters>
289+
<parameter key="mailer.some_parameter" type="string">true</parameter>
290+
</parameters>
291+
292+
<!-- after parsing
293+
$container->getParameter('mailer.some_parameter'); // returns "true"
294+
-->
295+
296+
.. note::
297+
298+
This is not available for Yaml and PHP, because they already have built-in
299+
support for the PHP keywords.
300+
301+
Referencing Services with Parameters
302+
------------------------------------
303+
304+
A parameter can also reference to a service. While doing so, it specifies an
305+
invalid behaviour.
306+
307+
Yaml
308+
~~~~
309+
310+
Start the string with ``@``, ``@@`` or ``@?`` to reference a service in Yaml.
311+
312+
* ``@mailer`` references to the ``mailer`` service. If the service does not
313+
exists, an exception will be thrown;
314+
* ``@?mailer`` references to the ``mailer`` service. If the service does not
315+
exists, it will be ignored;
316+
317+
Xml
318+
~~~
319+
320+
In XML, use the ``service`` type. The behaviour if the service does not exists
321+
can be specified using the ``on-invalid`` argument (it can be set to ``null``
322+
to return ``null`` or ``ignored`` to let the container ignore the error, if
323+
not specified it throws an exception).
324+
325+
Php
326+
~~~
327+
328+
In PHP, you can use the
329+
:class:`Symfony\\Component\\DependencyInjection\\Reference` class to reference
330+
a service.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy