@@ -174,10 +174,7 @@ public function typecastSaveRow(Model $model, array $row): array
174
174
175
175
$ field = $ model ->getField ($ fieldName );
176
176
177
- // SQL Expression cannot be converted
178
- if (!$ value instanceof \Atk4 \Data \Persistence \Sql \Expressionable) {
179
- $ value = $ this ->typecastSaveField ($ field , $ value );
180
- }
177
+ $ value = $ this ->typecastSaveField ($ field , $ value );
181
178
182
179
// check null values for mandatory fields
183
180
if ($ value === null && $ field ->mandatory ) {
@@ -197,6 +194,10 @@ public function typecastSaveRow(Model $model, array $row): array
197
194
* NOTE: Please DO NOT perform "actual" field mapping here, because data
198
195
* may be "aliased" from SQL persistencies or mapped depending on persistence
199
196
* driver.
197
+ *
198
+ * @param array<string, scalar|null> $row
199
+ *
200
+ * @return array<string, mixed>
200
201
*/
201
202
public function typecastLoadRow (Model $ model , array $ row ): array
202
203
{
@@ -232,11 +233,15 @@ public function typecastSaveField(Field $field, $value)
232
233
return null ;
233
234
}
234
235
236
+ // SQL Expression cannot be converted
237
+ if ($ value instanceof Persistence \Sql \Expressionable) {
238
+ return $ value ;
239
+ }
240
+
235
241
try {
236
242
$ v = $ this ->_typecastSaveField ($ field , $ value );
237
- if ($ v !== null && !is_scalar ($ v ) && !$ v instanceof Persistence \Sql \Expressionable) { // @phpstan-ignore-line
238
- throw (new Exception ('Unexpected non-scalar value ' ))
239
- ->addMoreInfo ('type ' , get_debug_type ($ v ));
243
+ if ($ v !== null && !is_scalar ($ v )) { // @phpstan-ignore-line
244
+ throw new Exception ('Unexpected non-scalar value ' );
240
245
}
241
246
242
247
return $ v ;
@@ -250,14 +255,16 @@ public function typecastSaveField(Field $field, $value)
250
255
* Cast specific field value from the way how it's stored inside
251
256
* persistence to a PHP format.
252
257
*
253
- * @param mixed $value
258
+ * @param scalar|null $value
254
259
*
255
260
* @return mixed
256
261
*/
257
262
public function typecastLoadField (Field $ field , $ value )
258
263
{
259
264
if ($ value === null ) {
260
265
return null ;
266
+ } elseif (!is_scalar ($ value )) {
267
+ throw new Exception ('Unexpected non-scalar value ' );
261
268
}
262
269
263
270
try {
@@ -274,7 +281,7 @@ public function typecastLoadField(Field $field, $value)
274
281
*
275
282
* @param mixed $value
276
283
*
277
- * @return scalar|Persistence\Sql\Expressionable| null
284
+ * @return scalar|null
278
285
*/
279
286
protected function _typecastSaveField (Field $ field , $ value )
280
287
{
@@ -310,7 +317,7 @@ protected function _typecastSaveField(Field $field, $value)
310
317
* This is the actual field typecasting, which you can override in your
311
318
* persistence to implement necessary typecasting.
312
319
*
313
- * @param mixed $value
320
+ * @param scalar|null $value
314
321
*
315
322
* @return mixed
316
323
*/
0 commit comments