@@ -47,19 +47,9 @@ public function process(ContainerBuilder $container)
47
47
}
48
48
49
49
$ defaultBag = new ParameterBag ($ resolvingBag ->all ());
50
- $ envTypes = $ resolvingBag ->getProvidedTypes ();
51
50
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
- }
51
+ $ values = $ this ->getPlaceholderValues ($ env , $ defaultBag , $ resolvingBag ->getProvidedTypes ());
52
+
63
53
foreach ($ placeholders as $ placeholder ) {
64
54
BaseNode::setPlaceholder ($ placeholder , $ values );
65
55
}
@@ -100,4 +90,50 @@ public function getExtensionConfig(): array
100
90
$ this ->extensionConfig = [];
101
91
}
102
92
}
93
+
94
+ /**
95
+ * @param array<string, list<string>> $envTypes
96
+ *
97
+ * @return array<string, mixed>
98
+ */
99
+ private function getPlaceholderValues (string $ env , ParameterBag $ defaultBag , array $ envTypes ): array
100
+ {
101
+ if (false === $ i = strpos ($ env , ': ' )) {
102
+ [$ default , $ defaultType ] = $ this ->getParameterDefaultAndDefaultType ("env( $ env) " , $ defaultBag );
103
+
104
+ return [$ defaultType => $ default ];
105
+ }
106
+
107
+ $ prefix = substr ($ env , 0 , $ i );
108
+ if ('default ' === $ prefix ) {
109
+ $ parts = explode (': ' , $ env );
110
+ array_shift ($ parts ); // Remove 'default' prefix
111
+ $ parameter = array_shift ($ parts ); // Retrieve and remove parameter
112
+
113
+ [$ defaultParameter , $ defaultParameterType ] = $ this ->getParameterDefaultAndDefaultType ($ parameter , $ defaultBag );
114
+
115
+ return [
116
+ $ defaultParameterType => $ defaultParameter ,
117
+ ...$ this ->getPlaceholderValues (implode (': ' , $ parts ), $ defaultBag , $ envTypes ),
118
+ ];
119
+ }
120
+
121
+ $ values = [];
122
+ foreach ($ envTypes [$ prefix ] ?? ['string ' ] as $ type ) {
123
+ $ values [$ type ] = self ::TYPE_FIXTURES [$ type ] ?? null ;
124
+ }
125
+
126
+ return $ values ;
127
+ }
128
+
129
+ /**
130
+ * @return array{0: string, 1: string}
131
+ */
132
+ private function getParameterDefaultAndDefaultType (string $ name , ParameterBag $ defaultBag ): array
133
+ {
134
+ $ default = $ defaultBag ->has ($ name ) ? $ defaultBag ->get ($ name ) : self ::TYPE_FIXTURES ['string ' ];
135
+ $ defaultType = null !== $ default ? get_debug_type ($ default ) : 'string ' ;
136
+
137
+ return [$ default , $ defaultType ];
138
+ }
103
139
}
0 commit comments