Skip to content

Commit 826591d

Browse files
committed
Merge pull request #2882 from WouterJ/parameter_types
Documented all parameter types
2 parents d7e9df0 + fc913c0 commit 826591d

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
@@ -285,3 +285,67 @@ key, and define the type as ``constant``.
285285
# app/config/config.yml
286286
imports:
287287
- { resource: parameters.xml }
288+
289+
PHP keywords in XML
290+
-------------------
291+
292+
By default, ``true``, ``false`` and ``null`` in XML are converted to the PHP
293+
keywords (respectively ``true``, ``false`` and ``null``):
294+
295+
.. code-block:: xml
296+
297+
<parameters>
298+
<parameter key="mailer.send_all_in_once">false</parameters>
299+
</parameters>
300+
301+
<!-- after parsing
302+
$container->getParameter('mailer.send_all_in_once'); // returns false
303+
-->
304+
305+
To disable this behaviour, use the ``string`` type:
306+
307+
.. code-block:: xml
308+
309+
<parameters>
310+
<parameter key="mailer.some_parameter" type="string">true</parameter>
311+
</parameters>
312+
313+
<!-- after parsing
314+
$container->getParameter('mailer.some_parameter'); // returns "true"
315+
-->
316+
317+
.. note::
318+
319+
This is not available for Yaml and PHP, because they already have built-in
320+
support for the PHP keywords.
321+
322+
Referencing Services with Parameters
323+
------------------------------------
324+
325+
A parameter can also reference to a service. While doing so, it specifies an
326+
invalid behaviour.
327+
328+
Yaml
329+
~~~~
330+
331+
Start the string with ``@``, ``@@`` or ``@?`` to reference a service in Yaml.
332+
333+
* ``@mailer`` references to the ``mailer`` service. If the service does not
334+
exists, an exception will be thrown;
335+
* ``@?mailer`` references to the ``mailer`` service. If the service does not
336+
exists, it will be ignored;
337+
338+
Xml
339+
~~~
340+
341+
In XML, use the ``service`` type. The behaviour if the service does not exists
342+
can be specified using the ``on-invalid`` argument (it can be set to ``null``
343+
to return ``null`` or ``ignored`` to let the container ignore the error, if
344+
not specified it throws an exception).
345+
346+
Php
347+
~~~
348+
349+
In PHP, you can use the
350+
:class:`Symfony\\Component\\DependencyInjection\\Reference` class to reference
351+
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