8000 minor #8728 Change service override docs (weaverryan) · symfony/symfony-docs@3e00ed1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e00ed1

Browse files
committed
minor #8728 Change service override docs (weaverryan)
This PR was squashed before being merged into the 4.0 branch (closes #8728). Discussion ---------- Change service override docs Updated to use Flex namespaces & directories. Also, since the kernel is a compiler pass... I think you can just put this all in the Kernel, right? Commits ------- 09fb4b1 Clarifying that our code is just additions da666af Change service override docs
2 parents 554d8e7 + 09fb4b1 commit 3e00ed1

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

bundles/override.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@ Services & Configuration
4646
If you want to modify service definitions of another bundle, you can use a compiler
4747
pass to change the class of the service or to modify method calls. In the following
4848
example, the implementing class for the ``original-service-id`` is changed to
49-
``Acme\DemoBundle\YourService``::
49+
``App\YourService``:
5050

51-
// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
52-
namespace Acme\DemoBundle\DependencyInjection\Compiler;
51+
.. code-block:: diff
5352
54-
use Acme\DemoBundle\YourService;
55-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
56-
use Symfony\Component\DependencyInjection\ContainerBuilder;
53+
// src/Kernel.php
54+
namespace App;
5755
58-
class OverrideServiceCompilerPass implements CompilerPassInterface
56+
// ...
57+
+ use App\Service\YourService;
58+
+ use Symfony\Component\DependencyInjection\ContainerBuilder;
59+
60+
class Kernel extends BaseKernel
5961
{
60-
public function process(ContainerBuilder $container)
61-
{
62-
$definition = $container->getDefinition('original-service-id');
63-
$definition->setClass(YourService::class);
64-
}
62+
+ public function process(ContainerBuilder $container)
63+
+ {
64+
+ $definition = $container->findDefinition('original-service-id');
65+
+ $definition->setClass(YourService::class);
66+
+ }
6567
}
6668
6769
For more information on compiler passes, see :doc:`/service_container/compiler_passes`.

0 commit comments

Comments
 (0)
0