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