@@ -60,18 +60,17 @@ protected function renderTable(string $table, string $alias = null): string {
60
60
}
61
61
/**
62
62
*
63
- * @staticvar int $runtimeExpressionPrefix
64
63
* @param ExpressionInterface $expression
65
64
* @param PlatformInterface $platform
66
65
* @param null|string $namedParameterPrefix
67
66
* @return string
68
67
* @throws Exception\RuntimeException
69
68
*/
70
- protected function processExpression (ExpressionInterface $ expression , PlatformInterface $ platform , ?string $ namedParameterPrefix = null ): string {
69
+ protected function processExpression (ExpressionInterface $ expression ,
70
+ PlatformInterface $ platform ,
71
+ ?string $ namedParameterPrefix = null ): string {
71
72
$ namedParameterPrefix = ! $ namedParameterPrefix ? $ namedParameterPrefix : $ this ->processInfo ['paramPrefix ' ] .
72
73
$ namedParameterPrefix ;
73
- // static counter for the number of times this method was invoked across the PHP runtime
74
- static $ runtimeExpressionPrefix = 0 ;
75
74
76
75
$ namedParameterPrefix = preg_replace ('/\s/ ' , '__ ' , $ namedParameterPrefix );
77
76
@@ -80,57 +79,46 @@ protected function processExpression(ExpressionInterface $expression, PlatformIn
80
79
// initialize variables
81
80
$ parts = $ expression ->getExpressionData ();
82
81
83
- if (! isset ($ this ->instanceParameterIndex [$ namedParameterPrefix ])) {
84
- $ this ->instanceParameterIndex [$ namedParameterPrefix ] = 1 ;
85
- }
82
+ $ this ->instanceParameterIndex [$ namedParameterPrefix ] ??= 1 ;
86
83
87
84
$ expressionParamIndex = &$ this ->instanceParameterIndex [$ namedParameterPrefix ];
88
85
89
86
foreach ($ parts as $ part ) {
90
- // #7407: use $expression->getExpression() to get the unescaped
91
- // version of the expression
92
- if (is_string ($ part ) && $ expression instanceof Expression) {
93
- $ sql .= $ expression ->getExpression ();
94
- continue ;
95
- }
96
-
97
- // If it is a string, simply tack it onto the return sql
87
+ //
88
+ // If it is a string, use $expression->getExpression() to get the unescaped, or simply tack it onto the return sql
98
89
// "specification" string
99
90
if (is_string ($ part )) {
100
- $ sql .= $ part ;
91
+ $ sql .= $ expression instanceof Expression ? $ expression -> getExpression () : $ part ;
101
92
continue ;
102
93
}
103
94
104
95
if (! is_array ($ part )) {
105
- throw new Exception \RuntimeException ('Elements returned from getExpressionData() array must be a string or array. ' );
96
+ throw new Exception \RuntimeException ('Elements returned from getExpressionData() array must be a string or array. '
97
+ );
106
98
}
107
99
108
- // Process values and types (the middle and last position of the
109
- // expression data)
100
+ // Process values and types (the middle and last position of the expression data)
110
101
$ values = $ part [1 ];
111
- $ types = isset ($ part [2 ]) ? $ part [2 ] : [];
112
- foreach ($ values as $ vIndex => $ value ) {
113
- if (! isset ($ types [$ vIndex ])) {
114
- continue ;
115
- }
116
- $ type = $ types [$ vIndex ];
117
- if ($ value instanceof Select) {
118
- // process sub-select
119
- $ values [$ vIndex ] = '( ' . $ this ->processSubSelect ($ value , $ platform ) . ') ' ;
120
- } elseif ($ value instanceof ExpressionInterface) {
121
- // recursive call to satisfy nested expressions
122
- $ values [$ vIndex ] = $ this ->processExpression ($ value , $ platform ,
123
- $ namedParameterPrefix . $ vIndex . 'subpart ' );
124
- } elseif ($ type == ExpressionInterface::TYPE_IDENTIFIER ) {
125
- $ values [$ vIndex ] = $ platform ->quoteIdentifierInFragment ($ value );
126
- } elseif ($ type == ExpressionInterface::TYPE_VALUE ) {
127
- // if not a preparable statement, simply quote the value and move on
128
- $ values [$ vIndex ] = $ platform ->quoteValue ($ value );
129
- } elseif ($ type == ExpressionInterface::TYPE_LITERAL ) {
130
- $ values [$ vIndex ] = $ value ;
131
- }
102
+ if (! empty ($ part [2 ])) {
103
+ $ types = $ part [2 ];
104
+ foreach ($ values as $ vIndex => &$ value )
105
+ if (isset ($ types [$ vIndex ])) {
106
+ $ value = match (true ) {
107
+ $ value instanceof Select => '( ' . $ this ->processSubSelect ($ value , $ platform ) . ') ' ,
108
+ $ value instanceof ExpressionInterface => $ this ->processExpression ($ value ,
109
+ $ platform ,
110
+ $ namedParameterPrefix . $ vIndex . 'subpart '
111
+ ),
112
+ default => match ($ types [$ vIndex ]) {
113
+ ExpressionInterface::TYPE_IDENTIFIER => $ platform ->quoteIdentifierInFragment ($ value ),
114
+ ExpressionInterface::TYPE_VALUE => $ platform ->quoteValue ($ value ),
115
+ ExpressionInterface::TYPE_LITERAL => $ value ,
116
+ default => $ value
117
+ }
118
+ };
119
+ }
120
+ unset($ value );
132
121
}
133
-
134
122
// After looping the values, interpolate them into the sql string
135
123
// (they might be placeholder names, or values)
136
124
$ sql .= vsprintf ($ part [0 ], $ values );
@@ -163,7 +151,8 @@ protected function createSqlFromSpecificationAndParameters(string|array $specifi
163
151
}
164
152
165
153
if (! isset ($ specificationString )) {
166
- throw new Exception \RuntimeException ('A number of parameters was found that is not supported by this specification ' );
154
+ throw new Exception \RuntimeException ('A number of parameters was found that is not supported by this specification '
155
+ );
167
156
}
168
157
169
158
$ topParameters = [];
@@ -179,7 +168,9 @@ protected function createSqlFromSpecificationAndParameters(string|array $specifi
179
168
180
169
if (! isset ($ paramSpecs [$ position ][$ ppCount ])) {
181
170
throw new Exception \RuntimeException (sprintf ('A number of parameters (%d) was found that is not supported by this specification ' ,
182
- $ ppCount ));
171
+ $ ppCount
172
+ )
173
+ );
183
174
}
184
175
if (is_string ($ multiParamsForPosition )) {
185
176
$ multiParamValues [] = sprintf ($ paramSpecs [$ position ][$ ppCount ], $ multiParamsForPosition );
@@ -192,7 +183,9 @@ protected function createSqlFromSpecificationAndParameters(string|array $specifi
192
183
$ ppCount = count ($ paramsForPosition );
193
184
if (! isset ($ paramSpecs [$ position ][$ ppCount ])) {
194
185
throw new Exception \RuntimeException (sprintf ('A number of parameters (%d) was found that is not supported by this specification ' ,
195
- $ ppCount ));
186
+ $ ppCount
187
+ )
188
+ );
196
189
}
197
190
$ topParameters [] = vsprintf ($ paramSpecs [$ position ][$ ppCount ], $ paramsForPosition );
198
191
} else {
@@ -245,16 +238,17 @@ protected function processJoin(Join $joins, PlatformInterface $platform): ?array
245
238
$ platform ->getIdentifierSeparator () : '' ) . $ platform ->quoteIdentifier ($ joinName [0 ]);
246
239
} elseif ($ joinName instanceof Select) {
247
240
$ joinName = '( ' . $ this ->processSubSelect ($ joinName , $ platform ) . ') ' ;
248
- } elseif (is_string ($ joinName ) || (is_object ($ joinName ) && is_callable ([
249
- $ joinName ,
250
- '__toString '
251
- ]))) {
241
+ } elseif (is_string ($ joinName ) || (is_object ($ joinName ) && method_exists ($ joinName , '__toString ' ))) {
252
242
if ($ platform ->shoueldQuoteOtherTable ()) {
253
243
$ joinName = $ platform ->quoteIdentifier ($ joinName );
244
+ } else {
245
+ $ joinName = (string )$ joinName ;
254
246
}
255
247
} else {
256
248
throw new Exception \InvalidArgumentException (sprintf ('Join name expected to be Expression|TableIdentifier|Select|string, "%s" given ' ,
257
- gettype ($ joinName )));
249
+ gettype ($ joinName )
250
+ )
251
+ );
258
252
}
259
253
260
254
$ joinSpecArgArray [$ j ] = [
@@ -293,7 +287,9 @@ protected function processJoin(Join $joins, PlatformInterface $platform): ?array
293
287
* @param null|string $namedParameterPrefix
294
288
* @return string
295
289
*/
296
- protected function resolveColumnValue (mixed $ column , PlatformInterface $ platform , ?string $ namedParameterPrefix = null ): string {
290
+ protected function resolveColumnValue (mixed $ column ,
291
+ PlatformInterface $ platform ,
292
+ ?string $ namedParameterPrefix = null ): string {
297
293
$ namedParameterPrefix = ! $ namedParameterPrefix ? $ namedParameterPrefix : $ this ->processInfo ['paramPrefix ' ] .
298
294
$ namedParameterPrefix ;
299
295
$ isIdentifier = false ;
@@ -324,8 +320,7 @@ protected function resolveColumnValue(mixed $column, PlatformInterface $platform
324
320
}
325
321
$ column = (string )$ column ;
326
322
327
- return $ isIdentifier ? $ fromTable .
328
- $ platform ->quoteIdentifierInFragment ($ column ) : $ platform ->quoteValue ($ column );
323
+ return $ isIdentifier ? $ fromTable . $ platform ->quoteIdentifierInFragment ($ column ) : $ platform ->quoteValue ($ column );
329
324
}
330
325
/**
331
326
*
0 commit comments