‪TYPO3CMS  ‪main
Services.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 namespace ‪TYPO3\CMS\Core;
6 
7 use Psr\Http\Server\MiddlewareInterface;
8 use Psr\Http\Server\RequestHandlerInterface;
9 use Psr\Log\LoggerAwareInterface;
10 use Symfony\Component\Console\Attribute\AsCommand;
11 use Symfony\Component\DependencyInjection\ChildDefinition;
12 use Symfony\Component\DependencyInjection\ContainerBuilder;
13 use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
14 use Symfony\Component\Messenger\Attribute\AsMessageHandler;
16 
17 return static function (ContainerConfigurator $container, ContainerBuilder $containerBuilder) {
18  $containerBuilder->registerForAutoconfiguration(SingletonInterface::class)->addTag('typo3.singleton');
19  $containerBuilder->registerForAutoconfiguration(LoggerAwareInterface::class)->addTag('psr.logger_aware');
20 
21  // Services, to be read from container-aware dispatchers (on demand), therefore marked 'public'
22  $containerBuilder->registerForAutoconfiguration(MiddlewareInterface::class)->addTag('typo3.middleware');
23  $containerBuilder->registerForAutoconfiguration(RequestHandlerInterface::class)->addTag('typo3.request_handler');
24 
25  $containerBuilder->registerAttributeForAutoconfiguration(
26  AsEventListener::class,
27  static function (ChildDefinition $definition, ‪AsEventListener $attribute, \Reflector $reflector): void {
28  $definition->addTag(
30  [
31  'identifier' => $attribute->identifier,
32  'event' => $attribute->event,
33  'method' => $attribute->method ?? ($reflector instanceof \ReflectionMethod ? $reflector->getName() : null),
34  'before' => $attribute->before,
35  'after' => $attribute->after,
36  ]
37  );
38  }
39  );
40 
41  $containerBuilder->registerAttributeForAutoconfiguration(
42  AsMessageHandler::class,
43  static function (ChildDefinition $definition, AsMessageHandler $attribute, \Reflector $reflector): void {
44  $definition->addTag(
45  'messenger.message_handler',
46  [
47  'bus' => $attribute->bus,
48  'fromTransport' => $attribute->fromTransport,
49  'handles' => $attribute->handles,
50  'method' => $attribute->method ?? ($reflector instanceof \ReflectionMethod ? $reflector->getName() : null),
51  'priority' => $attribute->priority,
52  ]
53  );
54  }
55  );
56 
57  $containerBuilder->registerAttributeForAutoconfiguration(
58  AsCommand::class,
59  static function (ChildDefinition $definition, AsCommand $attribute): void {
60  $commands = explode('|', $attribute->name);
61  $hidden = false;
62  $name = array_shift($commands);
63 
64  if ($name === '') {
65  // Symfony AsCommand attribute encodes hidden flag as an empty command name
66  $hidden = true;
67  $name = array_shift($commands);
68  }
69 
70  if ($name === null) {
71  // This happens in case no name and no aliases are given
72  // @todo Throw exception
73  return;
74  }
75 
76  $definition->addTag(
77  'console.command',
78  [
79  'command' => $name,
80  'description' => $attribute->description,
81  'hidden' => $hidden,
82  // The `schedulable` flag is not configurable via symfony attribute parameters, use sane defaults
83  'schedulable' => true,
84  ]
85  );
86 
87  foreach ($commands as $name) {
88  $definition->addTag(
89  'console.command',
90  [
91  'command' => $name,
92  'hidden' => $hidden,
93  'alias' => true,
94  ]
95  );
96  }
97  }
98  );
99 
100  $containerBuilder->addCompilerPass(new DependencyInjection\SingletonPass('typo3.singleton'));
101  $containerBuilder->addCompilerPass(new DependencyInjection\LoggerAwarePass('psr.logger_aware'));
102  $containerBuilder->addCompilerPass(new DependencyInjection\LoggerInterfacePass());
103  $containerBuilder->addCompilerPass(new DependencyInjection\MfaProviderPass('mfa.provider'));
104  $containerBuilder->addCompilerPass(new DependencyInjection\SoftReferenceParserPass('softreference.parser'));
105  $containerBuilder->addCompilerPass(new DependencyInjection\ListenerProviderPass('event.listener'));
106  $containerBuilder->addCompilerPass(new DependencyInjection\PublicServicePass('typo3.middleware'));
107  $containerBuilder->addCompilerPass(new DependencyInjection\PublicServicePass('typo3.request_handler'));
108  $containerBuilder->addCompilerPass(new DependencyInjection\ConsoleCommandPass('console.command'));
109  $containerBuilder->addCompilerPass(new DependencyInjection\MessageHandlerPass('messenger.message_handler'));
110  $containerBuilder->addCompilerPass(new DependencyInjection\MessengerMiddlewarePass('messenger.middleware'));
111  $containerBuilder->addCompilerPass(new DependencyInjection\AutowireInjectMethodsPass());
112 };
‪TYPO3\CMS\Core\Attribute\AsEventListener
Definition: AsEventListener.php:25
‪TYPO3\CMS\Core\Attribute\AsEventListener\TAG_NAME
‪const TAG_NAME
Definition: AsEventListener.php:26
‪TYPO3\CMS\Core