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,38 @@ public function process(ContainerBuilder $container): void
4142
4243 $ container ->setParameter ('doctrine.dbal.connection_factory.types ' , $ types );
4344 }
45+
46+ /** @return array<string, array> */
47+ private function findTaggedResourceIds (ContainerBuilder $ container ): array
48+ {
49+ $ tagName = 'doctrine.dbal.type ' ;
50+ if (method_exists ($ container , 'findTaggedResourceIds ' )) {
51+ return $ container ->findTaggedResourceIds ($ tagName );
52+ }
53+
54+ // Needed to keep compatibility with Symfony < 7.3
55+ $ tags = [];
56+ foreach ($ container ->getDefinitions () as $ id => $ definition ) {
57+ if (! $ definition ->hasTag ($ tagName )) {
58+ continue ;
59+ }
60+
61+ if (! $ definition ->hasTag ('container.excluded ' )) {
62+ throw new InvalidArgumentException (sprintf ('The resource "%s" tagged "%s" is missing the "container.excluded" tag. ' , $ id , $ tagName ));
63+ }
64+
65+ $ class = $ container ->getParameterBag ()->resolveValue ($ definition ->getClass ());
66+ if (! $ class || $ definition ->isAbstract ()) {
67+ throw new InvalidArgumentException (sprintf ('The resource "%s" tagged "%s" must have a class and not be abstract. ' , $ id , $ tagName ));
68+ }
69+
70+ if ($ definition ->getClass () !== $ class ) {
71+ $ definition ->setClass ($ class );
72+ }
73+
74+ $ tags [$ id ] = $ definition ->getTag ($ tagName );
75+ }
76+
77+ return $ tags ;
78+ }
4479}
0 commit comments