Skip to content

Commit 22c9404

Browse files
committed
[#3232][#3022] Making many small tweaks thanks to @wouterj and @xabbuh
1 parent 4d50f34 commit 22c9404

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

book/includes/_service_container_my_mailer.rst.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<?xml version="1.0" encoding="UTF-8" ?>
1515
<container xmlns="http://symfony.com/schema/dic/services"
1616
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
17+
xsi:schemaLocation="http://symfony.com/schema/dic/services
18+
http://symfony.com/schema/dic/services/services-1.0.xsd"
19+
>
1820

1921
<services>
2022
<service id="my_mailer" class="Acme\HelloBundle\Mailer">

book/service_container.rst

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,17 +630,20 @@ the work of instantiating the classes.
630630
Using the Expression Language
631631
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
632632

633+
.. versionadded:: 2.4
634+
The Expression Language functionality was introduced in Symfony 2.4.
635+
633636
The service container also supports an "expression" that allows you to inject
634637
very specific values into a service.
635638

636639
For example, suppose you have a third service (not shown here), called ``mailer_configuration``,
637-
which has a ``getMailerMethod`` method on it, which will return a string
640+
which has a ``getMailerMethod()`` method on it, which will return a string
638641
like ``sendmail`` based on some configuration. Remember that the first argument
639642
to the ``my_mailer`` service is the simple string ``sendmail``:
640643

641644
.. include includes/_service_container_my_mailer.rst.inc
642645
643-
But instead of hardcoding this, how could we get this value from the ``getMailerMethod``
646+
But instead of hardcoding this, how could we get this value from the ``getMailerMethod()``
644647
of the new ``mailer_configuration`` service? One way is to use an expression:
645648

646649
.. configuration-block::
@@ -659,7 +662,9 @@ of the new ``mailer_configuration`` service? One way is to use an expression:
659662
<?xml version="1.0" encoding="UTF-8" ?>
660663
<container xmlns="http://symfony.com/schema/dic/services"
661664
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
662-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
665+
xsi:schemaLocation="http://symfony.com/schema/dic/services
666+
http://symfony.com/schema/dic/services/services-1.0.xsd"
667+
>
663668
664669
<services>
665670
<service id="my_mailer" class="Acme\HelloBundle\Mailer">
@@ -672,10 +677,11 @@ of the new ``mailer_configuration`` service? One way is to use an expression:
672677
673678
// app/config/config.php
674679
use Symfony\Component\DependencyInjection\Definition;
680+
use Symfony\Component\ExpressionLanguage\Expression;
675681
676682
$container->setDefinition('my_mailer', new Definition(
677683
'Acme\HelloBundle\Mailer',
678-
array(new Expression("service('mailer_configuration').getMailerMethod()"))
684+
array(new Expression('service("mailer_configuration").getMailerMethod()'))
679685
));
680686
681687
To learn more about the expression language syntax, see :doc:`/components/expression_language/syntax`.
@@ -694,15 +700,17 @@ via a ``container`` variable. Here's another example:
694700
695701
services:
696702
my_mailer:
697-
class: Acme\HelloBundle\Mailer
698-
arguments: ["@=container.hasParameter('some_param') ? parameter('some_param') : 'default_value'"]
703+
class: Acme\HelloBundle\Mailer
704+
arguments: ["@=container.hasParameter('some_param') ? parameter('some_param') : 'default_value'"]
699705
700706
.. code-block:: xml
701707
702708
<?xml version="1.0" encoding="UTF-8" ?>
703709
<container xmlns="http://symfony.com/schema/dic/services"
704710
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
705-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
711+
xsi:schemaLocation="http://symfony.com/schema/dic/services
712+
http://symfony.com/schema/dic/services/services-1.0.xsd"
713+
>
706714
707715
<services>
708716
<service id="my_mailer" class="Acme\HelloBundle\Mailer">
@@ -714,10 +722,13 @@ via a ``container`` variable. Here's another example:
714722
.. code-block:: php
715723
716724
use Symfony\Component\DependencyInjection\Definition;
725+
use Symfony\Component\ExpressionLanguage\Expression;
717726
718727
$container->setDefinition('my_mailer', new Definition(
719728
'Acme\HelloBundle\Mailer',
720-
array(new Expression("@=container.hasParameter('some_param') ? parameter('some_param') : 'default_value'"))
729+
array(new Expression(
730+
"@=container.hasParameter('some_param') ? parameter('some_param') : 'default_value'"
731+
))
721732
));
722733
723734
Expressions can be used in ``parameters``, ``arguments``, ``properties``,

0 commit comments

Comments
 (0)