‪TYPO3CMS  ‪main
SingletonPass.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
21 use Symfony\Component\DependencyInjection\ContainerBuilder;
22 
26 final class ‪SingletonPass implements CompilerPassInterface
27 {
31  private ‪$tagName;
32 
33  public function ‪__construct(string ‪$tagName)
34  {
35  $this->tagName = ‪$tagName;
36  }
37 
41  public function ‪process(ContainerBuilder $container)
42  {
43  foreach ($container->findTaggedServiceIds($this->tagName) as $id => $tags) {
44  $definition = $container->findDefinition($id);
45  if (!$definition->isAutoconfigured() || $definition->isAbstract()) {
46  continue;
47  }
48 
49  // Singletons need to be shared (that's symfony's configuration for singletons)
50  // They need to be public to be available for legacy makeInstance usage.
51  $definition->setShared(true)->setPublic(true);
52  }
53  }
54 }
‪TYPO3\CMS\Core\DependencyInjection\SingletonPass
Definition: SingletonPass.php:27
‪TYPO3\CMS\Core\DependencyInjection
Definition: AutowireInjectMethodsPass.php:18
‪TYPO3\CMS\Core\DependencyInjection\SingletonPass\$tagName
‪string $tagName
Definition: SingletonPass.php:30
‪TYPO3\CMS\Core\DependencyInjection\SingletonPass\process
‪process(ContainerBuilder $container)
Definition: SingletonPass.php:40
‪TYPO3\CMS\Core\DependencyInjection\SingletonPass\__construct
‪__construct(string $tagName)
Definition: SingletonPass.php:32