Skip to content

Commit 35f48ee

Browse files
committed
minor #19081 [DependencyInjection] simplify compiler pass example (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] simplify compiler pass example Commits ------- d348603 simplify compiler pass example
2 parents a24e265 + d348603 commit 35f48ee

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

testing.rst

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -639,32 +639,27 @@ to remove the ``kernel.reset`` tag from some services in your test environment::
639639
// src/Kernel.php
640640
namespace App;
641641

642-
use App\DependencyInjection\Compiler\CustomPass;
643642
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
643+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
644644
use Symfony\Component\DependencyInjection\ContainerBuilder;
645645
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
646646

647-
class Kernel extends BaseKernel
647+
class Kernel extends BaseKernel implements CompilerPassInterface
648648
{
649649
use MicroKernelTrait;
650650

651651
// ...
652652

653-
protected function build(ContainerBuilder $container): void
653+
protected function process(ContainerBuilder $container): void
654654
{
655655
if ('test' === $this->environment) {
656-
$container->addCompilerPass(new class() implements CompilerPassInterface {
657-
public function process(ContainerBuilder $container): void
658-
{
659-
// prevents the security token to be cleared
660-
$container->getDefinition('security.token_storage')->clearTag('kernel.reset');
661-
662-
// prevents Doctrine entities to be detached
663-
$container->getDefinition('doctrine')->clearTag('kernel.reset');
664-
665-
// ...
666-
}
667-
});
656+
// prevents the security token to be cleared
657+
$container->getDefinition('security.token_storage')->clearTag('kernel.reset');
658+
659+
// prevents Doctrine entities to be detached
660+
$container->getDefinition('doctrine')->clearTag('kernel.reset');
661+
662+
// ...
668663
}
669664
}
670665
}

0 commit comments

Comments
 (0)