From 04903f792ef23cc4a556a290a7f92f46da6ff76c Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sat, 6 May 2017 00:24:49 +0200 Subject: [PATCH] Update some examples using 3.3 features --- console/commands_as_services.rst | 18 ++-- form/type_guesser.rst | 3 +- reference/dic_tags.rst | 161 +++++++++------------------- routing/custom_route_loader.rst | 3 +- service_container/alias_private.rst | 2 +- 5 files changed, 57 insertions(+), 130 deletions(-) diff --git a/console/commands_as_services.rst b/console/commands_as_services.rst index e6c0e341712..82025d0ec87 100644 --- a/console/commands_as_services.rst +++ b/console/commands_as_services.rst @@ -27,9 +27,7 @@ with ``console.command``: # app/config/config.yml services: - app.command.my_command: - class: AppBundle\Command\MyCommand - tags: [console.command] + AppBundle\Command\MyCommand: [console.command] .. code-block:: xml @@ -41,8 +39,7 @@ with ``console.command``: http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -53,8 +50,7 @@ with ``console.command``: // app/config/config.php use AppBundle\Command\MyCommand; - $container - ->register('app.command.my_command', MyCommand::class) + $container->register(MyCommand::class) ->addTag('console.command') ; @@ -131,8 +127,7 @@ inject the ``command.default_name`` parameter: command.default_name: Javier services: - app.command.my_command: - class: AppBundle\Command\MyCommand + AppBundle\Command\MyCommand: arguments: ["%command.default_name%"] tags: [console.command] @@ -150,8 +145,7 @@ inject the ``command.default_name`` parameter: - + %command.default_name% @@ -166,7 +160,7 @@ inject the ``command.default_name`` parameter: $container->setParameter('command.default_name', 'Javier'); $container - ->register('app.command.my_command', MyCommand::class) + ->register(MyCommand::class) ->setArguments(array('%command.default_name%')) ->addTag('console.command') ; diff --git a/form/type_guesser.rst b/form/type_guesser.rst index df69e998c36..595018f5edb 100644 --- a/form/type_guesser.rst +++ b/form/type_guesser.rst @@ -188,8 +188,7 @@ and tag it with ``form.type_guesser``: services: # ... - AppBundle\Form\TypeGuesser\PHPDocTypeGuesser: - tags: [form.type_guesser] + AppBundle\Form\TypeGuesser\PHPDocTypeGuesser: [form.type_guesser] .. code-block:: xml diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index d33d8198e1b..c9dbc7d4af6 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -91,9 +91,7 @@ And then register it as a tagged service: .. code-block:: yaml services: - app.custom_assetic_worker: - class: AppBundle\Assetic\CustomWorker - tags: [assetic.factory_worker] + AppBundle\Assetic\CustomWorker: [assetic.factory_worker] .. code-block:: xml @@ -103,7 +101,7 @@ And then register it as a tagged service: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -114,7 +112,7 @@ And then register it as a tagged service: use AppBundle\Assetic\CustomWorker; $container - ->register('app.custom_assetic_worker', CustomWorker::class) + ->register(CustomWorker::class) ->addTag('assetic.factory_worker') ; @@ -151,8 +149,7 @@ Second, define a service: .. code-block:: yaml services: - app.custom_assetic_filter: - class: AppBundle\Assetic\CustomFilter + AppBundle\Assetic\CustomFilter: tags: - { name: assetic.filter, alias: my_filter } @@ -164,7 +161,7 @@ Second, define a service: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -175,7 +172,7 @@ Second, define a service: use AppBundle\Assetic\CustomFilter; $container - ->register('app.custom_assetic_filter', CustomFilter::class) + ->register(CustomFilter::class) ->addTag('assetic.filter', array('alias' => 'my_filter')) ; @@ -466,8 +463,7 @@ Then register this class and tag it with ``kernel.cache_clearer``: .. code-block:: yaml services: - my_cache_clearer: - class: AppBundle\Cache\MyClearer + AppBundle\Cache\MyClearer: tags: [kernel.cache_clearer] .. code-block:: xml @@ -478,7 +474,7 @@ Then register this class and tag it with ``kernel.cache_clearer``: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -488,8 +484,7 @@ Then register this class and tag it with ``kernel.cache_clearer``: use AppBundle\Cache\MyClearer; - $container - ->register('my_cache_clearer', MyClearer::class) + $container->register(MyClearer::class) ->addTag('kernel.cache_clearer') ; @@ -546,8 +541,7 @@ tag: .. code-block:: yaml services: - app.warmer.my_custom_warmer: - class: AppBundle\Cache\MyCustomWarmer + AppBundle\Cache\MyCustomWarmer: tags: - { name: kernel.cache_warmer, priority: 0 } @@ -559,9 +553,7 @@ tag: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -571,8 +563,7 @@ tag: use AppBundle\Cache\MyCustomWarmer; - $container - ->register('app.warmer.my_custom_warmer', MyCustomWarmer::class) + $container->register(MyCustomWarmer::class) ->addTag('kernel.cache_warmer', array('priority' => 0)) ; @@ -636,9 +627,7 @@ configuration and tag it with ``kernel.event_subscriber``: .. code-block:: yaml services: - app.custom_subscriber: - class: AppBundle\EventListener\CustomSubscriber - tags: [kernel.event_subscriber] + AppBundle\EventListener\CustomSubscriber: [kernel.event_subscriber] .. code-block:: xml @@ -648,10 +637,7 @@ configuration and tag it with ``kernel.event_subscriber``: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + @@ -661,11 +647,7 @@ configuration and tag it with ``kernel.event_subscriber``: use AppBundle\EventListener\CustomSubscriber; - $container - ->register( - 'app.custom_subscriber', - CustomSubscriber::class - ) + $container->register(CustomSubscriber::class) ->addTag('kernel.event_subscriber') ; @@ -705,8 +687,7 @@ channel when injecting the logger in a service. .. code-block:: yaml services: - app.custom_logger: - class: AppBundle\Log\CustomLogger + AppBundle\Log\CustomLogger: arguments: ['@logger'] tags: - { name: monolog.logger, channel: acme } @@ -719,7 +700,7 @@ channel when injecting the logger in a service. xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -731,7 +712,7 @@ channel when injecting the logger in a service. use AppBundle\Log\CustomLogger; use Symfony\Component\DependencyInjection\Reference; - $container->register('app.custom_logger', CustomLogger::class) + $container->register(CustomLogger::class) ->addArgument(new Reference('logger')) ->addTag('monolog.logger', array('channel' => 'acme')); @@ -763,9 +744,7 @@ You can add a processor globally: .. code-block:: yaml services: - my_service: - class: Monolog\Processor\IntrospectionProcessor - tags: [monolog.processor] + Monolog\Processor\IntrospectionProcessor: [monolog.processor] .. code-block:: xml @@ -775,7 +754,7 @@ You can add a processor globally: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -785,8 +764,7 @@ You can add a processor globally: use Monolog\Processor\IntrospectionProcessor; - $container - ->register('my_service', IntrospectionProcessor::class) + $container->register(IntrospectionProcessor::class) ->addTag('monolog.processor') ; @@ -803,8 +781,7 @@ attribute: .. code-block:: yaml services: - my_service: - class: Monolog\Processor\IntrospectionProcessor + Monolog\Processor\IntrospectionProcessor: tags: - { name: monolog.processor, handler: firephp } @@ -816,7 +793,7 @@ attribute: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -826,8 +803,7 @@ attribute: use Monolog\Processor\IntrospectionProcessor; - $container - ->register('my_service', IntrospectionProcessor::class) + $container->register(IntrospectionProcessor::class) ->addTag('monolog.processor', array('handler' => 'firephp')) ; @@ -840,8 +816,7 @@ You can also add a processor for a specific logging channel by using the .. code-block:: yaml services: - my_service: - class: Monolog\Processor\IntrospectionProcessor + Monolog\Processor\IntrospectionProcessor: tags: - { name: monolog.processor, channel: security } @@ -853,7 +828,7 @@ You can also add a processor for a specific logging channel by using the xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -863,8 +838,7 @@ You can also add a processor for a specific logging channel by using the use Monolog\Processor\IntrospectionProcessor; - $container - ->register('my_service', IntrospectionProcessor::class) + $container->register(IntrospectionProcessor::class) ->addTag('monolog.processor', array('channel' => 'security')) ; @@ -886,9 +860,7 @@ of your configuration and tag it with ``routing.loader``: .. code-block:: yaml services: - app.custom_routing_loader: - class: AppBundle\Routing\CustomLoader - tags: [routing.loader] + AppBundle\Routing\CustomLoader: [routing.loader] .. code-block:: xml @@ -898,10 +870,7 @@ of your configuration and tag it with ``routing.loader``: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + @@ -912,7 +881,7 @@ of your configuration and tag it with ``routing.loader``: use AppBundle\Routing\CustomLoader; $container - ->register('app.custom_routing_loader', CustomLoader::class) + ->register(CustomLoader::class) ->addTag('routing.loader') ; @@ -1026,8 +995,7 @@ templates): .. code-block:: yaml services: - app.templating_helper: - class: AppBundle\Templating\AppHelper + AppBundle\Templating\AppHelper: tags: - { name: templating.helper, alias: alias_name } @@ -1039,10 +1007,7 @@ templates): xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + @@ -1053,7 +1018,7 @@ templates): use AppBundle\Templating\AppHelper; $container - ->register('app.templating_helper', AppHelper::class) + ->register(AppHelper::class) ->addTag('templating.helper', array('alias' => 'alias_name')) ; @@ -1079,8 +1044,7 @@ Now, register your loader as a service and tag it with ``translation.loader``: .. code-block:: yaml services: - app.translation.my_custom_loader: - class: AppBundle\Translation\MyCustomLoader + AppBundle\Translation\MyCustomLoader: tags: - { name: translation.loader, alias: bin } @@ -1092,10 +1056,7 @@ Now, register your loader as a service and tag it with ``translation.loader``: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + @@ -1105,11 +1066,7 @@ Now, register your loader as a service and tag it with ``translation.loader``: use AppBundle\Translation\MyCustomLoader; - $container - ->register( - 'app.translation.my_custom_loader', - MyCustomLoader::class - ) + $container->register(MyCustomLoader::class) ->addTag('translation.loader', array('alias' => 'bin')) ; @@ -1178,8 +1135,7 @@ required option: ``alias``, which defines the name of the extractor:: .. code-block:: yaml services: - app.custom_translation_extractor: - class: App\Translation\CustomExtractor + App\Translation\CustomExtractor: tags: - { name: translation.extractor, alias: foo } @@ -1191,10 +1147,7 @@ required option: ``alias``, which defines the name of the extractor:: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + @@ -1204,7 +1157,7 @@ required option: ``alias``, which defines the name of the extractor:: use AppBundle\Translation\CustomExtractor; - $container->register('app.custom_translation_extractor', CustomExtractor::class) + $container->register(CustomExtractor::class) ->addTag('translation.extractor', array('alias' => 'foo')); translation.dumper @@ -1238,8 +1191,7 @@ This is the name that's used to determine which dumper should be used. .. code-block:: yaml services: - app.json_translation_dumper: - class: AppBundle\Translation\JsonFileDumper + AppBundle\Translation\JsonFileDumper: tags: - { name: translation.dumper, alias: json } @@ -1251,10 +1203,7 @@ This is the name that's used to determine which dumper should be used. xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + @@ -1264,7 +1213,7 @@ This is the name that's used to determine which dumper should be used. use AppBundle\Translation\JsonFileDumper; - $container->register('app.json_translation_dumper', JsonFileDumper::class) + $container->register(JsonFileDumper::class) ->addTag('translation.dumper', array('alias' => 'json')); .. seealso:: @@ -1287,9 +1236,7 @@ configuration and tag it with ``twig.extension``: .. code-block:: yaml services: - app.twig_extension: - class: AppBundle\Twig\AppExtension - tags: [twig.extension] + AppBundle\Twig\AppExtension: [twig.extension] .. code-block:: xml @@ -1299,10 +1246,7 @@ configuration and tag it with ``twig.extension``: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + @@ -1312,8 +1256,7 @@ configuration and tag it with ``twig.extension``: use AppBundle\Twig\AppExtension; - $container - ->register('app.twig_extension', AppExtension::class) + $container->register(AppExtension::class) ->addTag('twig.extension') ; @@ -1372,8 +1315,7 @@ the new loader and tag it with ``twig.loader``: .. code-block:: yaml services: - app.custom_twig_loader: - class: AppBundle\Twig\CustomLoader + AppBundle\Twig\CustomLoader: tags: - { name: twig.loader, priority: 0 } @@ -1385,10 +1327,7 @@ the new loader and tag it with ``twig.loader``: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + @@ -1398,11 +1337,7 @@ the new loader and tag it with ``twig.loader``: use AppBundle\Twig\CustomLoader; - $container - ->register( - 'app.custom_twig_loader', - CustomLoader::class - ) + $container->register(CustomLoader::class) ->addTag('twig.loader', array('priority' => 0)) ; diff --git a/routing/custom_route_loader.rst b/routing/custom_route_loader.rst index b1c332fb175..60e192e1840 100644 --- a/routing/custom_route_loader.rst +++ b/routing/custom_route_loader.rst @@ -147,8 +147,7 @@ Now define a service for the ``ExtraLoader``: services: # ... - AppBundle\Routing\ExtraLoader: - tags: [routing.loader] + AppBundle\Routing\ExtraLoader: [routing.loader] .. code-block:: xml diff --git a/service_container/alias_private.rst b/service_container/alias_private.rst index d32741e5e57..55c7447d8b0 100644 --- a/service_container/alias_private.rst +++ b/service_container/alias_private.rst @@ -68,7 +68,7 @@ from the container:: $container->get(Foo::class); This *may or may not work*, depending on how the container has optimized the -service instantiation and, even in the cases where it works, is +service instantiation and, even in the cases where it works, this possibility is deprecated. Simply said: A service should be marked as private if you do not want to access it directly from your code.