1111
1212use function array_key_exists ;
1313use function is_subclass_of ;
14+ use function method_exists ;
1415use function sprintf ;
1516
1617/** @internal */
@@ -20,7 +21,7 @@ public function process(ContainerBuilder $container): void
2021 {
2122 $ types = $ container ->getParameter ('doctrine.dbal.connection_factory.types ' );
2223
23- foreach ($ container ->findTaggedResourceIds (' doctrine.dbal.type ' ) as $ id => $ tags ) {
24+ foreach ($ this ->findTaggedResourceIds ($ container ) as $ id => $ tags ) {
2425 foreach ($ tags as $ tag ) {
2526 if (! array_key_exists ('name ' , $ tag )) {
2627 throw new InvalidArgumentException (sprintf ('The "name" attribute is mandatory for the "doctrine.dbal.type" tag on the "%s" type. ' , $ id ));
@@ -41,4 +42,41 @@ public function process(ContainerBuilder $container): void
4142
4243 $ container ->setParameter ('doctrine.dbal.connection_factory.types ' , $ types );
4344 }
45+
46+ /** @return array<string, array<array{name?: string}>> */
47+ private function findTaggedResourceIds (ContainerBuilder $ container ): array
48+ {
49+ $ tagName = 'doctrine.dbal.type ' ;
50+
51+ // Determine if the version of symfony/dependency-injection is >= 7.3
52+ /** @phpstan-ignore function.alreadyNarrowedType */
53+ if (method_exists ($ container , 'findTaggedResourceIds ' )) {
54+ return $ container ->findTaggedResourceIds ($ tagName );
55+ }
56+
57+ // Needed to keep compatibility with symfony/dependency-injection < 7.3
58+ $ tags = [];
59+ foreach ($ container ->getDefinitions () as $ id => $ definition ) {
60+ if (! $ definition ->hasTag ($ tagName )) {
61+ continue ;
62+ }
63+
64+ if (! $ definition ->hasTag ('container.excluded ' )) {
65+ throw new InvalidArgumentException (sprintf ('The resource "%s" tagged "%s" is missing the "container.excluded" tag. ' , $ id , $ tagName ));
66+ }
67+
68+ $ class = $ container ->getParameterBag ()->resolveValue ($ definition ->getClass ());
69+ if (! $ class || $ definition ->isAbstract ()) {
70+ throw new InvalidArgumentException (sprintf ('The resource "%s" tagged "%s" must have a class and not be abstract. ' , $ id , $ tagName ));
71+ }
72+
73+ if ($ definition ->getClass () !== $ class ) {
74+ $ definition ->setClass ($ class );
75+ }
76+
77+ $ tags [$ id ] = $ definition ->getTag ($ tagName );
78+ }
79+
80+ return $ tags ;
81+ }
4482}
0 commit comments