‪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;
15 
16 return static function (ContainerConfigurator $container, ContainerBuilder $containerBuilder) {
17  $containerBuilder->registerForAutoconfiguration(SingletonInterface::class)->addTag('typo3.singleton');
18  $containerBuilder->registerForAutoconfiguration(LoggerAwareInterface::class)->addTag('psr.logger_aware');
19 
20  // Services, to be read from container-aware dispatchers (on demand), therefore marked 'public'
21  $containerBuilder->registerForAutoconfiguration(MiddlewareInterface::class)->addTag('typo3.middleware');
22  $containerBuilder->registerForAutoconfiguration(RequestHandlerInterface::class)->addTag('typo3.request_handler');
23 
24  $containerBuilder->registerAttributeForAutoconfiguration(
25  AsEventListener::class,
26  static function (ChildDefinition $definition, ‪AsEventListener $attribute, \Reflector $reflector): void {
27  $definition->addTag(
29  [
30  'identifier' => $attribute->identifier,
31  'event' => $attribute->event,
32  'method' => $attribute->method ?? ($reflector instanceof \ReflectionMethod ? $reflector->getName() : null),
33  'before' => $attribute->before,
34  'after' => $attribute->after,
35  ]
36  );
37  }
38  );
39 
40  $containerBuilder->registerAttributeForAutoconfiguration(
41  AsCommand::class,
42  static function (ChildDefinition $definition, AsCommand $attribute): void {
43  $commands = explode('|', $attribute->name);
44  $hidden = false;
45  $name = array_shift($commands);
46 
47  if ($name === '') {
48  // Symfony AsCommand attribute encodes hidden flag as an empty command name
49  $hidden = true;
50  $name = array_shift($commands);
51  }
52 
53  if ($name === null) {
54  // This happens in case no name and no aliases are given
55  // @todo Throw exception
56  return;
57  }
58 
59  $definition->addTag(
60  'console.command',
61  [
62  'command' => $name,
63  'description' => $attribute->description,
64  'hidden' => $hidden,
65  // The `schedulable` flag is not configurable via symfony attribute parameters, use sane defaults
66  'schedulable' => true,
67  ]
68  );
69 
70  foreach ($commands as $name) {
71  $definition->addTag(
72  'console.command',
73  [
74  'command' => $name,
75  'hidden' => $hidden,
76  'alias' => true,
77  ]
78  );
79  }
80  }
81  );
82 
83  $containerBuilder->addCompilerPass(new DependencyInjection\SingletonPass('typo3.singleton'));
84  $containerBuilder->addCompilerPass(new DependencyInjection\LoggerAwarePass('psr.logger_aware'));
85  $containerBuilder->addCompilerPass(new DependencyInjection\LoggerInterfacePass());
86  $containerBuilder->addCompilerPass(new DependencyInjection\MfaProviderPass('mfa.provider'));
87  $containerBuilder->addCompilerPass(new DependencyInjection\SoftReferenceParserPass('softreference.parser'));
88  $containerBuilder->addCompilerPass(new DependencyInjection\ListenerProviderPass('event.listener'));
89  $containerBuilder->addCompilerPass(new DependencyInjection\PublicServicePass('typo3.middleware'));
90  $containerBuilder->addCompilerPass(new DependencyInjection\PublicServicePass('typo3.request_handler'));
91  $containerBuilder->addCompilerPass(new DependencyInjection\ConsoleCommandPass('console.command'));
92  $containerBuilder->addCompilerPass(new DependencyInjection\MessageHandlerPass('messenger.message_handler'));
93  $containerBuilder->addCompilerPass(new DependencyInjection\MessengerMiddlewarePass('messenger.middleware'));
94  $containerBuilder->addCompilerPass(new DependencyInjection\AutowireInjectMethodsPass());
95 };
‪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