From f24b3fea25740920654924b690ff0c8e5df19c9c Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 27 Oct 2016 09:57:50 +0200 Subject: [PATCH 1/3] Remove suggestion to change the `.class` parameters To my knowledge, this practice has been discouraged and the corresponding configuration hooks have been dropped in Symfony 3.0. --- bundles/override.rst | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/bundles/override.rst b/bundles/override.rst index d67a47154f6..fa8e5c29d03 100644 --- a/bundles/override.rst +++ b/bundles/override.rst @@ -37,39 +37,10 @@ If the controller is a service, see the next section on how to override it. Services & Configuration ------------------------ -In order to override/extend a service, there are two options. First, you can -set the parameter holding the service's class name to your own class by setting -it in ``app/config/config.yml``. This of course is only possible if the class name is -defined as a parameter in the service config of the bundle containing the -service. For example, to override the class used for Symfony's ``translator`` -service, you would override the ``translator.class`` parameter. Knowing exactly -which parameter to override may take some research. For the translator, the -parameter is defined and used in the ``Resources/config/translation.xml`` file -in the core FrameworkBundle: - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/config.yml - parameters: - translator.class: Acme\HelloBundle\Translation\Translator - - .. code-block:: xml - - - - Acme\HelloBundle\Translation\Translator - - - .. code-block:: php - - // app/config/config.php - $container->setParameter('translator.class', 'Acme\HelloBundle\Translation\Translator'); - -Secondly, if the class is not available as a parameter, you want to make sure the -class is always overridden when your bundle is used or if you need to modify -something beyond just the class name, you should use a compiler pass:: +If you want to modify service definitions of another bundle, you can use a compiler +pass to change the class of the service or to modify method calls. In the following +example, the implementing class for the ``original-service-id`` is changed to +``Acme\DemoBundle\YourService`. // src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php namespace Acme\DemoBundle\DependencyInjection\Compiler; @@ -86,12 +57,7 @@ something beyond just the class name, you should use a compiler pass:: } } -In this example you fetch the service definition of the original service, and set -its class name to your own class. - -See :doc:`/service_container/compiler_passes` for information on how to use -compiler passes. If you want to do something beyond just overriding the class, -like adding a method call, you can only use the compiler pass method. +For more information on compiler passes, see :doc:`/service_container/compiler_passes`. Entities & Entity Mapping ------------------------- From 2cf8b1f404fe78e79b1d2d1b66861c7d7762f088 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 27 Oct 2016 11:21:57 +0200 Subject: [PATCH 2/3] Add missing backtick --- bundles/override.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/override.rst b/bundles/override.rst index fa8e5c29d03..c3653463356 100644 --- a/bundles/override.rst +++ b/bundles/override.rst @@ -40,7 +40,7 @@ Services & Configuration If you want to modify service definitions of another bundle, you can use a compiler pass to change the class of the service or to modify method calls. In the following example, the implementing class for the ``original-service-id`` is changed to -``Acme\DemoBundle\YourService`. +``Acme\DemoBundle\YourService``. // src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php namespace Acme\DemoBundle\DependencyInjection\Compiler; From 5cd4f79f07df2ee1959ccbe8513cce70db65f58f Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 27 Oct 2016 14:30:00 +0200 Subject: [PATCH 3/3] Use a double colon so the following paragraph is indented as code section --- bundles/override.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/override.rst b/bundles/override.rst index c3653463356..698119fe92e 100644 --- a/bundles/override.rst +++ b/bundles/override.rst @@ -40,7 +40,7 @@ Services & Configuration If you want to modify service definitions of another bundle, you can use a compiler pass to change the class of the service or to modify method calls. In the following example, the implementing class for the ``original-service-id`` is changed to -``Acme\DemoBundle\YourService``. +``Acme\DemoBundle\YourService``:: // src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php namespace Acme\DemoBundle\DependencyInjection\Compiler;