[FEATURE] Add symfony dependency injection for core and extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / DependencyInjection / SingletonPass.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\DependencyInjection;
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
18 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19 use Symfony\Component\DependencyInjection\ContainerBuilder;
20
21 /**
22 * @internal
23 */
24 final class SingletonPass implements CompilerPassInterface
25 {
26 /**
27 * @var string
28 */
29 private $tagName;
30
31 /**
32 * @param string $tagName
33 */
34 public function __construct(string $tagName)
35 {
36 $this->tagName = $tagName;
37 }
38
39 /**
40 * @param ContainerBuilder $container
41 */
42 public function process(ContainerBuilder $container)
43 {
44 foreach ($container->findTaggedServiceIds($this->tagName) as $id => $tags) {
45 $definition = $container->findDefinition($id);
46 if (!$definition->isAutoconfigured() || $definition->isAbstract()) {
47 continue;
48 }
49
50 // Singletons need to be shared (that's symfony's configuration for singletons)
51 // They need to be public to be available for legacy makeInstance usage.
52 $definition->setShared(true)->setPublic(true);
53 }
54 }
55 }