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