@@ -316,14 +316,15 @@ private function parseFields(?string $poolName, array $fields, ?array &$data, bo
316
316
}
317
317
318
318
$ isPk = $ field ['ordinal_position ' ] > 0 ;
319
- [$ phpType , $ phpDefinitionType ] = $ this ->dbFieldTypeToPhp ($ field );
319
+ [$ phpType , $ phpDefinitionType, $ typeConvert ] = $ this ->dbFieldTypeToPhp ($ field );
320
320
$ data ['fields ' ][] = [
321
321
'name ' => $ field ['attname ' ],
322
322
'varName ' => Text::toCamelName ($ field ['attname ' ]),
323
323
'type ' => $ type = ('_ ' === $ field ['typname ' ][0 ] ? substr ($ field ['typname ' ], 1 ) : $ field ['typname ' ]),
324
324
'ndims ' => $ field ['attndims ' ],
325
325
'phpType ' => $ phpType . '|null ' ,
326
326
'phpDefinitionType ' => $ phpDefinitionType ,
327
+ 'typeConvert ' => $ typeConvert ,
327
328
'length ' => $ length ,
328
329
'accuracy ' => $ accuracy ,
329
330
'nullable ' => 'f ' === $ field ['attnotnull ' ],
@@ -359,27 +360,27 @@ private function renderTemplate(string $template, array $data): string
359
360
}
360
361
361
362
public const DB_FIELD_TYPE_MAP = [
362
- 'int ' => ['int ' , '?int ' ],
363
- 'int2 ' => ['int ' , '?int ' ],
364
- 'int4 ' => ['int ' , '?int ' ],
365
- 'int8 ' => ['int ' , '?int ' ],
366
- 'integer ' => ['int ' , '?int ' ],
367
- 'smallint ' => ['int ' , '?int ' ],
368
- 'bigint ' => ['int ' , '?int ' ],
369
- 'smallserial ' => ['int ' , '?int ' ],
370
- 'serial ' => ['int ' , '?int ' ],
371
- 'bigserial ' => ['int ' , '?int ' ],
372
- 'serial2 ' => ['int ' , '?int ' ],
373
- 'serial4 ' => ['int ' , '?int ' ],
374
- 'serial8 ' => ['int ' , '?int ' ],
375
- 'bool ' => ['bool ' , '?bool ' ],
376
- 'boolean ' => ['bool ' , '?bool ' ],
377
- 'double ' => ['float ' , '?float ' ],
378
- 'float4 ' => ['float ' , '?float ' ],
379
- 'float8 ' => ['float ' , '?float ' ],
363
+ 'int ' => ['int ' , '?int ' , ' (int) ' ],
364
+ 'int2 ' => ['int ' , '?int ' , ' (int) ' ],
365
+ 'int4 ' => ['int ' , '?int ' , ' (int) ' ],
366
+ 'int8 ' => ['int ' , '?int ' , ' (int) ' ],
367
+ 'integer ' => ['int ' , '?int ' , ' (int) ' ],
368
+ 'smallint ' => ['int ' , '?int ' , ' (int) ' ],
369
+ 'bigint ' => ['int ' , '?int ' , ' (int) ' ],
370
+ 'smallserial ' => ['int ' , '?int ' , ' (int) ' ],
371
+ 'serial ' => ['int ' , '?int ' , ' (int) ' ],
372
+ 'bigserial ' => ['int ' , '?int ' , ' (int) ' ],
373
+ 'serial2 ' => ['int ' , '?int ' , ' (int) ' ],
374
+ 'serial4 ' => ['int ' , '?int ' , ' (int) ' ],
375
+ 'serial8 ' => ['int ' , '?int ' , ' (int) ' ],
376
+ 'bool ' => ['bool ' , '?bool ' , ' (bool) ' ],
377
+ 'boolean ' => ['bool ' , '?bool ' , ' (bool) ' ],
378
+ 'double ' => ['float ' , '?float ' , ' (float) ' ],
379
+ 'float4 ' => ['float ' , '?float ' , ' (float) ' ],
380
+ 'float8 ' => ['float ' , '?float ' , ' (float) ' ],
380
381
'numeric ' => ['string|float|int ' , \PHP_VERSION_ID >= 80000 ? 'string|float|int|null ' : '' , '' ],
381
- 'json ' => ['\\' . \Imi \Util \LazyArrayObject::class . '|array ' , '' ],
382
- 'jsonb ' => ['\\' . \Imi \Util \LazyArrayObject::class . '|array ' , '' ],
382
+ 'json ' => ['\\' . \Imi \Util \LazyArrayObject::class . '|array ' , '' , '' ],
383
+ 'jsonb ' => ['\\' . \Imi \Util \LazyArrayObject::class . '|array ' , '' , '' ],
383
384
];
384
385
385
386
/**
@@ -399,11 +400,15 @@ private function dbFieldTypeToPhp(array $field): array
399
400
$ type = $ field ['typname ' ];
400
401
}
401
402
402
- $ result = self ::DB_FIELD_TYPE_MAP [$ type ] ?? ['string ' , '?string ' ];
403
+ $ result = self ::DB_FIELD_TYPE_MAP [$ type ] ?? ['string ' , '?string ' , '' ];
403
404
if ($ isArray )
404
405
{
405
- $ result [0 ] .= 'array ' ;
406
- $ result [1 ] = '?array ' ;
406
+ $ count = $ field ['attndims ' ];
407
+ $ result = [
408
+ str_repeat ('array< ' , $ count ) . $ result [0 ] . str_repeat ('> ' , $ count ),
409
+ '?array ' ,
410
+ '' ,
411
+ ];
407
412
}
408
413
409
414
return $ result ;
0 commit comments