‪TYPO3CMS  ‪main
TypeConverterPass.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;
25 
31 final class ‪TypeConverterPass implements CompilerPassInterface
32 {
33  private string ‪$tagName;
34 
35  public function ‪__construct(string ‪$tagName)
36  {
37  $this->tagName = ‪$tagName;
38  }
39 
43  public function ‪process(ContainerBuilder $container): void
44  {
45  $typeConverterRegistryDefinition = $container->findDefinition(TypeConverterRegistry::class);
46 
47  foreach ($container->findTaggedServiceIds($this->tagName) as $serviceName => $tags) {
48  $definition = $container->findDefinition($serviceName);
49  if (!$definition->isAutoconfigured() || $definition->isAbstract()) {
50  continue;
51  }
52 
53  $definition->setPublic(true);
54 
55  foreach ($tags as $attributes) {
56  if (!isset($attributes['sources'])) {
58  sprintf(
59  'Configuration for TypeConverter "%s" misses the "sources" attribute.',
60  $serviceName
61  ),
62  1638376684
63  );
64  }
65 
66  $sources = ‪GeneralUtility::trimExplode(',', (string)$attributes['sources'], true);
67 
68  if ($sources === []) {
70  sprintf(
71  'The sources attribute of the configuration of TypeConverter "%s" contains an empty list.',
72  $serviceName
73  ),
74  1638376687
75  );
76  }
77 
78  if (!($attributes['target'] ?? false)) {
80  sprintf(
81  'Configuration for TypeConverter "%s" misses a valid "target" attribute.',
82  $serviceName
83  ),
84  1638376689
85  );
86  }
87 
88  $typeConverterRegistryDefinition->addMethodCall('add', [
89  $definition,
90  (int)($attributes['priority'] ?? 10),
91  $sources,
92  $attributes['target'],
93  ]);
94  }
95  }
96  }
97 }
‪TYPO3\CMS\Extbase\DependencyInjection
Definition: TypeConverterPass.php:18
‪TYPO3\CMS\Extbase\DependencyInjection\TypeConverterPass\__construct
‪__construct(string $tagName)
Definition: TypeConverterPass.php:35
‪TYPO3\CMS\Extbase\Property\Exception\InvalidTypeConverterConfigurationException
Definition: InvalidTypeConverterConfigurationException.php:22
‪TYPO3\CMS\Extbase\Property\TypeConverterRegistry
Definition: TypeConverterRegistry.php:28
‪TYPO3\CMS\Extbase\DependencyInjection\TypeConverterPass
Definition: TypeConverterPass.php:32
‪TYPO3\CMS\Extbase\DependencyInjection\TypeConverterPass\$tagName
‪string $tagName
Definition: TypeConverterPass.php:33
‪TYPO3\CMS\Extbase\DependencyInjection\TypeConverterPass\process
‪process(ContainerBuilder $container)
Definition: TypeConverterPass.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822