‪TYPO3CMS  10.4
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 
36  public function ‪__construct(string ‪$tagName)
37  {
38  $this->tagName = ‪$tagName;
39  }
40 
44  public function ‪process(ContainerBuilder $container)
45  {
46  foreach ($container->findTaggedServiceIds($this->tagName) as $id => $tags) {
47  $definition = $container->findDefinition($id);
48  if (!$definition->isAutoconfigured() || $definition->isAbstract()) {
49  continue;
50  }
51 
52  // Singletons need to be shared (that's symfony's configuration for singletons)
53  // They need to be public to be available for legacy makeInstance usage.
54  $definition->setShared(true)->setPublic(true);
55  }
56  }
57 }
‪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:43
‪TYPO3\CMS\Core\DependencyInjection\SingletonPass\__construct
‪__construct(string $tagName)
Definition: SingletonPass.php:35