@@ -49,17 +49,8 @@ public function process(ContainerBuilder $container)
4949 $ defaultBag = new ParameterBag ($ resolvingBag ->all ());
5050 $ envTypes = $ resolvingBag ->getProvidedTypes ();
5151 foreach ($ resolvingBag ->getEnvPlaceholders () + $ resolvingBag ->getUnusedEnvPlaceholders () as $ env => $ placeholders ) {
52- $ values = [];
53- if (false === $ i = strpos ($ env , ': ' )) {
54- $ default = $ defaultBag ->has ("env( $ env) " ) ? $ defaultBag ->get ("env( $ env) " ) : self ::TYPE_FIXTURES ['string ' ];
55- $ defaultType = null !== $ default ? get_debug_type ($ default ) : 'string ' ;
56- $ values [$ defaultType ] = $ default ;
57- } else {
58- $ prefix = substr ($ env , 0 , $ i );
59- foreach ($ envTypes [$ prefix ] ?? ['string ' ] as $ type ) {
60- $ values [$ type ] = self ::TYPE_FIXTURES [$ type ] ?? null ;
61- }
62- }
52+ $ values = $ this ->getPlaceholderValues ($ env , $ defaultBag , $ envTypes );
53+
6354 foreach ($ placeholders as $ placeholder ) {
6455 BaseNode::setPlaceholder ($ placeholder , $ values );
6556 }
@@ -100,4 +91,50 @@ public function getExtensionConfig(): array
10091 $ this ->extensionConfig = [];
10192 }
10293 }
94+
95+ /**
96+ * @param array<string, list<string>> $envTypes
97+ *
98+ * @return array<string, mixed>
99+ */
100+ private function getPlaceholderValues (string $ env , ParameterBag $ defaultBag , array $ envTypes ): array
101+ {
102+ if (false === $ i = strpos ($ env , ': ' )) {
103+ [$ default , $ defaultType ] = $ this ->getParameterDefaultAndDefaultType ("env( $ env) " , $ defaultBag );
104+
105+ return [$ defaultType => $ default ];
106+ }
107+
108+ $ prefix = substr ($ env , 0 , $ i );
109+ if ('default ' === $ prefix ) {
110+ $ parts = explode (': ' , $ env );
111+ array_shift ($ parts ); // Remove 'default' prefix
112+ $ parameter = array_shift ($ parts ); // Retrieve and remove parameter
113+
114+ [$ defaultParameter , $ defaultParameterType ] = $ this ->getParameterDefaultAndDefaultType ($ parameter , $ defaultBag );
115+
116+ return [
117+ $ defaultParameterType => $ defaultParameter ,
118+ ...$ this ->getPlaceholderValues (implode (': ' , $ parts ), $ defaultBag , $ envTypes ),
119+ ];
120+ }
121+
122+ $ values = [];
123+ foreach ($ envTypes [$ prefix ] ?? ['string ' ] as $ type ) {
124+ $ values [$ type ] = self ::TYPE_FIXTURES [$ type ] ?? null ;
125+ }
126+
127+ return $ values ;
128+ }
129+
130+ /**
131+ * @return array{0: string, 1: string}
132+ */
133+ private function getParameterDefaultAndDefaultType (string $ name , ParameterBag $ defaultBag ): array
134+ {
135+ $ default = $ defaultBag ->has ($ name ) ? $ defaultBag ->get ($ name ) : self ::TYPE_FIXTURES ['string ' ];
136+ $ defaultType = null !== $ default ? get_debug_type ($ default ) : 'string ' ;
137+
138+ return [$ default , $ defaultType ];
139+ }
103140}
0 commit comments