‪TYPO3CMS  10.4
Services.php
Go to the documentation of this file.
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\AbstractController::class)->addTag('extbase.prototype_controller');
14  $container->registerForAutoconfiguration(Mvc\Controller\ActionController::class)->addTag('extbase.action_controller');
15  $container->registerForAutoconfiguration(Mvc\View\ViewInterface::class)->addTag('extbase.view');
16 
17  $container->addCompilerPass(new class() implements CompilerPassInterface {
18  public function process(ContainerBuilder $container): void
19  {
20  foreach ($container->findTaggedServiceIds('extbase.request_handler') as $id => $tags) {
21  $container->findDefinition($id)->setPublic(true);
22  }
23  foreach ($container->findTaggedServiceIds('extbase.controller') as $id => $tags) {
24  $container->findDefinition($id)->setPublic(true);
25  }
26  foreach ($container->findTaggedServiceIds('extbase.prototype_controller') as $id => $tags) {
27  $container->findDefinition($id)->setShared(false);
28  }
29  foreach ($container->findTaggedServiceIds('extbase.action_controller') as $id => $tags) {
30  $container->findDefinition($id)->setShared(false);
31  }
32  foreach ($container->findTaggedServiceIds('extbase.view') as $id => $tags) {
33  $container->findDefinition($id)->setShared(false)->setPublic(true);
34  }
35 
36  // Push alias definition defined in symfony into the extbase container
37  // 'aliasDefinitions' is a private property of the Symfony ContainerBuilder class
38  // but as 'alias' statements an not be tagged, that is the only way to retrieve
39  // these aliases to map them to the extbase container
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