@@ -2,9 +2,9 @@ The Dependency Injection Tags
2
2
=============================
3
3
4
4
Dependency Injection Tags are little strings that can be applied to a service
5
- to "flag" it to be used in some special way. For example, if you have a service
6
- that you would like to register as a listener to one of Symfony's core events,
7
- you can flag it with the ``kernel.event_listener `` tag.
5
+ to "flag" it to be used in some special way. For example, if you have a
6
+ service that you would like to register as a listener to one of Symfony's
7
+ core events, you can flag it with the ``kernel.event_listener `` tag.
8
8
9
9
You can learn a little bit more about "tags" by reading the ":ref: `book-service-container-tags `"
10
10
section of the Service Container chapter.
@@ -296,12 +296,13 @@ form.type_extension
296
296
297
297
**Purpose**: Create a custom " form extension"
298
298
299
- Form type extensions are a way for you took " hook into" the creation of any
300
- field in your form. For example, the addition of the CSRF token is done via
301
- a form type extension (:class:`Symfony\\Component\\Form\\Extension\\Csrf\\Type\\FormTypeCsrfExtension`).
299
+ Form type extensions are a way for you took " hook into" the creation of
300
+ any field in your form. For example, the addition of the CSRF token is done
301
+ via a form type extension
302
+ (:class:`Symfony\\Component\\Form\\Extension\\Csrf\\Type\\FormTypeCsrfExtension`).
302
303
303
- A form type extension can modify any part of any field in your form. To create
304
- a form type extension, first create a class that implements the
304
+ A form type extension can modify any part of any field in your form. To
305
+ create a form type extension, first create a class that implements the
305
306
:class:`Symfony\\Component\\Form\\FormTypeExtensionInterface` interface.
306
307
For simplicity, you'll often extend an
307
308
:class:`Symfony\\Component\\Form\\AbstractTypeExtension` class instead of
@@ -318,8 +319,8 @@ the interface directly::
318
319
// like buildForm(), buildView(), finishView(), setDefaultOptions()
319
320
}
320
321
321
- In order for Symfony to know about your form extension and use it, give it
322
- the ``form.type_extension`` tag:
322
+ In order for Symfony to know about your form extension and use it, give
323
+ it the ``form.type_extension`` tag:
323
324
324
325
.. configuration-block::
325
326
@@ -351,13 +352,16 @@ the ``form.type_extension`` tag:
351
352
.. code-block:: php
352
353
353
354
$container
354
- ->register('main.form.type.my_form_type_extension', 'Acme\MainBundle\Form\Type\MyFormTypeExtension')
355
+ ->register(
356
+ 'main.form.type.my_form_type_extension',
357
+ 'Acme\MainBundle\Form\Type\MyFormTypeExtension'
358
+ )
355
359
->addTag('form.type_extension', array('alias' => 'field'))
356
360
;
357
361
358
362
The ``alias`` key of the tag is the type of field that this extension should
359
- be applied to. For example, to apply the extension to any form/field, use the
360
- " form" value.
363
+ be applied to. For example, to apply the extension to any form/field, use
364
+ the " form" value.
361
365
362
366
.. _reference-dic-type_guesser:
363
367
@@ -379,7 +383,8 @@ metadata and Doctrine metadata (if you're using Doctrine) or Propel metadata
379
383
kernel.cache_clearer
380
384
--------------------
381
385
382
- **Purpose**: Register your service to be called during the cache clearing process
386
+ **Purpose**: Register your service to be called during the cache clearing
387
+ process
383
388
384
389
Cache clearing occurs whenever you call ``cache:clear`` command. If your
385
390
bundle caches files, you should add custom cache clearer for clearing those
@@ -438,14 +443,15 @@ Then register this class and tag it with ``kernel.cache_clearer``:
438
443
kernel.cache_warmer
439
444
-------------------
440
445
441
- **Purpose**: Register your service to be called during the cache warming process
446
+ **Purpose**: Register your service to be called during the cache warming
447
+ process
442
448
443
449
Cache warming occurs whenever you run the ``cache:warmup`` or ``cache:clear``
444
- task (unless you pass ``--no-warmup`` to ``cache:clear``). It is also run when
445
- handling the request, if it wasn't done by one of the commands yet. The purpose is
446
- to initialize any cache that will be needed by the application and prevent
447
- the first user from any significant " cache hit" where the cache is generated
448
- dynamically.
450
+ task (unless you pass ``--no-warmup`` to ``cache:clear``). It is also run
451
+ when handling the request, if it wasn't done by one of the commands yet.
452
+ The purpose is to initialize any cache that will be needed by the application
453
+ and prevent the first user from any significant " cache hit" where the cache
454
+ is generated dynamically.
449
455
450
456
To register your own cache warmer, first create a service that implements
451
457
the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` interface::
@@ -473,7 +479,8 @@ application without calling this cache warmer. In Symfony, optional warmers
473
479
are always executed by default (you can change this by using the
474
480
``--no-optional-warmers`` option when executing the command).
475
481
476
- To register your warmer with Symfony, give it the ``kernel.cache_warmer`` tag:
482
+ To register your warmer with Symfony, give it the ``kernel.cache_warmer``
483
+ tag:
477
484
478
485
.. configuration-block::
479
486
@@ -493,7 +500,9 @@ To register your warmer with Symfony, give it the ``kernel.cache_warmer`` tag:
493
500
xsi:schemaLocation=" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
494
501
495
502
<services>
496
- <service id=" main.warmer.my_custom_warmer" class=" Acme\MainBundle\Cache\MyCustomWarmer" >
503
+ <service id=" main.warmer.my_custom_warmer"
504
+ class=" Acme\MainBundle\Cache\MyCustomWarmer"
505
+ >
497
506
<tag name=" kernel.cache_warmer" priority=" 0" />
498
507
</service>
499
508
</services>
@@ -508,8 +517,8 @@ To register your warmer with Symfony, give it the ``kernel.cache_warmer`` tag:
508
517
509
518
.. note::
510
519
511
- The ``priority`` value is optional, and defaults to 0.
512
- The higher the priority, the sooner it gets executed.
520
+ The ``priority`` value is optional and defaults to 0. The higher the
521
+ priority, the sooner it gets executed.
513
522
514
523
Core Cache Warmers
515
524
~~~~~~~~~~~~~~~~~~
@@ -629,7 +638,7 @@ kernel.event_subscriber
629
638
**Purpose**: To subscribe to a set of different events/hooks in Symfony
630
639
631
640
To enable a custom subscriber, add it as a regular service in one of your
632
- configuration, and tag it with ``kernel.event_subscriber``:
641
+ configuration and tag it with ``kernel.event_subscriber``:
633
642
634
643
.. configuration-block::
635
644
@@ -661,7 +670,10 @@ configuration, and tag it with ``kernel.event_subscriber``:
661
670
.. code-block:: php
662
671
663
672
$container
664
- ->register('kernel.subscriber.your_subscriber_name', 'Fully\Qualified\Subscriber\Class\Name')
673
+ ->register(
674
+ 'kernel.subscriber.your_subscriber_name',
675
+ 'Fully\Qualified\Subscriber\Class\Name'
676
+ )
665
677
->addTag('kernel.event_subscriber')
666
678
;
667
679
@@ -672,8 +684,8 @@ configuration, and tag it with ``kernel.event_subscriber``:
672
684
673
685
.. note::
674
686
675
- If your service is created by a factory, you **MUST** correctly set the ``class``
676
- parameter for this tag to work correctly.
687
+ If your service is created by a factory, you **MUST** correctly set
688
+ the ``class`` parameter for this tag to work correctly.
677
689
678
690
kernel.fragment_renderer
679
691
------------------------
@@ -724,7 +736,9 @@ channel when injecting the logger in a service.
724
736
725
737
.. code-block:: php
726
738
727
- $definition = new Definition('Fully\Qualified\Loader\Class\Name', array(new Reference('logger'));
739
+ $definition = new Definition('Fully\Qualified\Loader\Class\Name', array(
740
+ new Reference('logger'),
741
+ ));
728
742
$definition->addTag('monolog.logger', array('channel' => 'acme'));
729
743
$container->setDefinition('my_service', $definition);
730
744
@@ -741,13 +755,13 @@ monolog.processor
741
755
742
756
**Purpose**: Add a custom processor for logging
743
757
744
- Monolog allows you to add processors in the logger or in the handlers to add
745
- extra data in the records. A processor receives the record as an argument and
746
- must return it after adding some extra data in the ``extra`` attribute of
747
- the record.
758
+ Monolog allows you to add processors in the logger or in the handlers to
759
+ add extra data in the records. A processor receives the record as an argument
760
+ and must return it after adding some extra data in the ``extra`` attribute
761
+ of the record.
748
762
749
- The built-in ``IntrospectionProcessor`` can be used to add the file, the line,
750
- the class and the method where the logger was triggered.
763
+ The built-in ``IntrospectionProcessor`` can be used to add the file, the
764
+ line, the class and the method where the logger was triggered.
751
765
752
766
You can add a processor globally:
753
767
@@ -821,9 +835,9 @@ attribute:
821
835
->addTag('monolog.processor', array('handler' => 'firephp'))
822
836
;
823
837
824
- You can also add a processor for a specific logging channel by using the ``channel``
825
- attribute. This will register the processor only for the ``security`` logging
826
- channel used in the Security component:
838
+ You can also add a processor for a specific logging channel by using the
839
+ ``channel`` attribute. This will register the processor only for the
840
+ ``security`` logging channel used in the Security component:
827
841
828
842
.. configuration-block::
829
843
@@ -867,7 +881,7 @@ routing.loader
867
881
**Purpose**: Register a custom service that loads routes
868
882
869
883
To enable a custom routing loader, add it as a regular service in one
870
- of your configuration, and tag it with ``routing.loader``:
884
+ of your configuration and tag it with ``routing.loader``:
871
885
872
886
.. configuration-block::
873
887
@@ -910,9 +924,9 @@ security.remember_me_aware
910
924
911
925
**Purpose**: To allow remember me authentication
912
926
913
- This tag is used internally to allow remember-me authentication to work. If
914
- you have a custom authentication method where a user can be remember-me authenticated,
915
- then you may need to use this tag.
927
+ This tag is used internally to allow remember-me authentication to work.
928
+ If you have a custom authentication method where a user can be remember-me
929
+ authenticated, then you may need to use this tag.
916
930
917
931
If your custom authentication factory extends
918
932
:class:`Symfony\\Bundle\\SecurityBundle\\DependencyInjection\\Security\\Factory\\AbstractFactory`
@@ -961,15 +975,16 @@ swiftmailer.default.plugin
961
975
962
976
**Purpose**: Register a custom SwiftMailer Plugin
963
977
964
- If you're using a custom SwiftMailer plugin (or want to create one), you can
965
- register it with SwiftMailer by creating a service for your plugin and tagging
966
- it with ``swiftmailer.default.plugin`` (it has no options).
978
+ If you're using a custom SwiftMailer plugin (or want to create one), you
979
+ can register it with SwiftMailer by creating a service for your plugin and
980
+ tagging it with ``swiftmailer.default.plugin`` (it has no options).
967
981
968
982
.. note::
969
983
970
984
``default`` in this tag is the name of the mailer. If you have multiple
971
- mailers configured or have changed the default mailer name for some reason,
972
- you should change it to the name of your mailer in order to use this tag.
985
+ mailers configured or have changed the default mailer name for some
986
+ reason, you should change it to the name of your mailer in order to
987
+ use this tag.
973
988
974
989
A SwiftMailer plugin must implement the ``Swift_Events_EventListener`` interface.
975
990
For more information on plugins, see `SwiftMailer's Plugin Documentation`_.
@@ -1028,8 +1043,8 @@ translation.loader
1028
1043
1029
1044
**Purpose**: To register a custom service that loads translations
1030
1045
1031
- By default, translations are loaded from the filesystem in a variety of different
1032
- formats (YAML, XLIFF, PHP, etc).
1046
+ By default, translations are loaded from the filesystem in a variety of
1047
+ different formats (YAML, XLIFF, PHP, etc).
1033
1048
1034
1049
.. seealso::
1035
1050
@@ -1068,19 +1083,23 @@ Now, register your loader as a service and tag it with ``translation.loader``:
1068
1083
.. code-block:: php
1069
1084
1070
1085
$container
1071
- ->register('main.translation.my_custom_loader', 'Acme\MainBundle\Translation\MyCustomLoader')
1086
+ ->register(
1087
+ 'main.translation.my_custom_loader',
1088
+ 'Acme\MainBundle\Translation\MyCustomLoader'
1089
+ )
1072
1090
->addTag('translation.loader', array('alias' => 'bin'))
1073
1091
;
1074
1092
1075
1093
The ``alias`` option is required and very important: it defines the file
1076
- " suffix" that will be used for the resource files that use this loader. For
1077
- example, suppose you have some custom ``bin`` format that you need to load.
1078
- If you have a ``bin`` file that contains French translations for the ``messages``
1079
- domain, then you might have a file ``app/Resources/translations/messages.fr.bin``.
1094
+ " suffix" that will be used for the resource files that use this loader.
1095
+ For example, suppose you have some custom ``bin`` format that you need to
1096
+ load. If you have a ``bin`` file that contains French translations for
1097
+ the ``messages`` domain, then you might have a file
1098
+ ``app/Resources/translations/messages.fr.bin``.
1080
1099
1081
- When Symfony tries to load the ``bin`` file, it passes the path to your custom
1082
- loader as the ``$resource`` argument. You can then perform any logic you need
1083
- on that file in order to load your translations.
1100
+ When Symfony tries to load the ``bin`` file, it passes the path to your
1101
+ custom loader as the ``$resource`` argument. You can then perform any logic
1102
+ you need on that file in order to load your translations.
1084
1103
1085
1104
If you're loading translations from a database, you'll still need a resource
1086
1105
file, but it might either be blank or contain a little bit of information
@@ -1090,7 +1109,8 @@ the ``load`` method on your custom loader.
1090
1109
translation.extractor
1091
1110
---------------------
1092
1111
1093
- **Purpose**: To register a custom service that extracts messages from a file
1112
+ **Purpose**: To register a custom service that extracts messages from a
1113
+ file
1094
1114
1095
1115
.. versionadded:: 2.1
1096
1116
The ability to add message extractors was introduced in Symfony 2.1.
@@ -1102,9 +1122,9 @@ has a :class:`Symfony\\Bridge\\Twig\\Translation\\TwigExtractor` and a
1102
1122
help to find and extract translation keys from Twig templates and PHP files.
1103
1123
1104
1124
You can create your own extractor by creating a class that implements
1105
- :class:`Symfony\\Component\\Translation\\Extractor\\ExtractorInterface` and
1106
- tagging the service with ``translation.extractor``. The tag has one required
1107
- option: ``alias``, which defines the name of the extractor::
1125
+ :class:`Symfony\\Component\\Translation\\Extractor\\ExtractorInterface`
1126
+ and tagging the service with ``translation.extractor``. The tag has one
1127
+ required option: ``alias``, which defines the name of the extractor::
1108
1128
1109
1129
// src/Acme/DemoBundle/Translation/FooExtractor.php
1110
1130
namespace Acme\DemoBundle\Translation;
@@ -1176,9 +1196,9 @@ translation.dumper
1176
1196
.. versionadded:: 2.1
1177
1197
The ability to add message dumpers was introduced in Symfony 2.1.
1178
1198
1179
- After an `Extractor <translation.extractor>`_ has extracted all messages from
1180
- the templates, the dumpers are executed to dump the messages to a translation
1181
- file in a specific format.
1199
+ After an `Extractor <translation.extractor>`_ has extracted all messages
1200
+ from the templates, the dumpers are executed to dump the messages to a
1201
+ translation file in a specific format.
1182
1202
1183
1203
Symfony already comes with many dumpers:
1184
1204
@@ -1245,7 +1265,7 @@ twig.extension
1245
1265
**Purpose**: To register a custom Twig Extension
1246
1266
1247
1267
To enable a Twig extension, add it as a regular service in one of your
1248
- configuration, and tag it with ``twig.extension``:
1268
+ configuration and tag it with ``twig.extension``:
1249
1269
1250
1270
.. configuration-block::
1251
1271
@@ -1277,7 +1297,10 @@ configuration, and tag it with ``twig.extension``:
1277
1297
.. code-block:: php
1278
1298
1279
1299
$container
1280
- ->register('twig.extension.your_extension_name', 'Fully\Qualified\Extension\Class\Name')
1300
+ ->register(
1301
+ 'twig.extension.your_extension_name',
1302
+ 'Fully\Qualified\Extension\Class\Name'
1303
+ )
1281
1304
->addTag('twig.extension')
1282
1305
;
1283
1306
@@ -1362,7 +1385,10 @@ the new loader and tag it with ``twig.loader``:
1362
1385
.. code-block:: php
1363
1386
1364
1387
$container
1365
- ->register('acme.demo_bundle.loader.some_twig_loader', 'Acme\DemoBundle\Loader\SomeTwigLoader')
1388
+ ->register(
1389
+ 'acme.demo_bundle.loader.some_twig_loader',
1390
+ 'Acme\DemoBundle\Loader\SomeTwigLoader'
1391
+ )
1366
1392
->addTag('twig.loader')
1367
1393
;
1368
1394
@@ -1383,14 +1409,15 @@ This tag provides a very uncommon piece of functionality that allows you
1383
1409
to perform some sort of action on an object right before it's validated.
1384
1410
For example, it's used by Doctrine to query for all of the lazily-loaded
1385
1411
data on an object before it's validated. Without this, some data on a Doctrine
1386
- entity would appear to be " missing" when validated, even though this is not
1387
- really the case.
1412
+ entity would appear to be " missing" when validated, even though this is
1413
+ not really the case.
1388
1414
1389
1415
If you do need to use this tag, just make a new class that implements the
1390
1416
:class:`Symfony\\Component\\Validator\\ObjectInitializerInterface` interface.
1391
1417
Then, tag it with the ``validator.initializer`` tag (it has no options).
1392
1418
1393
- For an example, see the ``EntityInitializer`` class inside the Doctrine Bridge.
1419
+ For an example, see the ``EntityInitializer`` class inside the Doctrine
1420
+ Bridge.
1394
1421
1395
1422
.. _`Twig's documentation`: http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension
1396
1423
.. _`Twig official extension repository`: https://github.com/twigphp/Twig-extensions
0 commit comments