Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc913c0

Browse filesBrowse files
committed
Documented all parameter types
1 parent 31443a3 commit fc913c0
Copy full SHA for fc913c0

File tree

Expand file treeCollapse file tree

1 file changed

+64
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+64
-0
lines changed

‎components/dependency_injection/parameters.rst

Copy file name to clipboardExpand all lines: components/dependency_injection/parameters.rst
+64Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.