[TASK] Update composer dev dependencies
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Configuration / Services.php
1 <?php
2
3 declare(strict_types=1);
4 namespace TYPO3\CMS\Extbase;
5
6 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7 use Symfony\Component\DependencyInjection\ContainerBuilder;
8 use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
9
10 return function (ContainerConfigurator $containerConfigurator, ContainerBuilder $container) {
11 $container->registerForAutoconfiguration(Mvc\RequestHandlerInterface::class)->addTag('extbase.request_handler');
12 $container->registerForAutoconfiguration(Mvc\Controller\ControllerInterface::class)->addTag('extbase.controller');
13 $container->registerForAutoconfiguration(Mvc\Controller\ActionController::class)->addTag('extbase.action_controller');
14 $container->registerForAutoconfiguration(Mvc\View\ViewInterface::class)->addTag('extbase.view');
15
16 $container->addCompilerPass(new class() implements CompilerPassInterface {
17 public function process(ContainerBuilder $container): void
18 {
19 foreach ($container->findTaggedServiceIds('extbase.request_handler') as $id => $tags) {
20 $container->findDefinition($id)->setPublic(true);
21 }
22 foreach ($container->findTaggedServiceIds('extbase.controller') as $id => $tags) {
23 $container->findDefinition($id)->setPublic(true);
24 }
25 foreach ($container->findTaggedServiceIds('extbase.action_controller') as $id => $tags) {
26 $container->findDefinition($id)->setShared(false);
27 }
28 foreach ($container->findTaggedServiceIds('extbase.view') as $id => $tags) {
29 $container->findDefinition($id)->setShared(false)->setPublic(true);
30 }
31
32 // Push alias definition defined in symfony into the extbase container
33 // 'aliasDefinitions' is a private property of the Symfony ContainerBuilder class
34 // but as 'alias' statements an not be tagged, that is the only way to retrieve
35 // these aliases to map them to the extbase container
36 // @deprecated since v11, will be removed in v12. Drop everything below.
37 $reflection = new \ReflectionClass(get_class($container));
38 $aliasDefinitions = $reflection->getProperty('aliasDefinitions');
39 $aliasDefinitions->setAccessible(true);
40
41 $extbaseContainer = $container->findDefinition(Object\Container\Container::class);
42 // Add registerImplementation() call for aliases
43 foreach ($aliasDefinitions->getValue($container) as $from => $alias) {
44 if (!class_exists($from) && !interface_exists($from)) {
45 continue;
46 }
47 $to = (string)$alias;
48 // Ignore aliases that are used to inject early instances into the container (instantiated during TYPO3 Bootstrap)
49 // and aliases that refer to service names instead of class names
50 if (strpos($to, '_early.') === 0 || !class_exists($to)) {
51 continue;
52 }
53
54 $extbaseContainer->addMethodCall('registerImplementation', [$from, $to]);
55 }
56 }
57 });
58 };