Skip to content

Commit a5eebd7

Browse files
authored
Adds ?integer, ?double, ?string, etc. cast types :)
Adds new cast types which are casting only if value !== null i.e. I've got an nullable col in my dbtable which stores strings (empty or not) and I'd like to have possibility to determine if string is null or ''; Now I cannot when I define casting as a string. with this PR if I define ?string in ``` protected $_options = [ 'casts' => [ 'usr_id' => 'integer', 'usr_usp_id' => 'integer', 'usr_provider_id' => 'string', 'usr_exc_id' => 'integer', 'usr_drs_id' => 'integer', 'usr_dlc_id' => '?string', 'usr_tzo_id' => 'integer', 'usr_email' => 'string', 'usr_password' => 'string', 'usr_first_name' => 'string', 'usr_last_name' => 'string', 'usr_nick_name' => 'string', 'usr_is_active' => 'boolean', 'usr_is_blocked' => 'boolean', 'usr_is_picture' => 'boolean', ], 'dates'=> ['usr_created_at', 'usr_updated_at'], 'datamap' => [] ]; ``` I will get NULL or '' for usr_dlc_id according to database value.
1 parent b8bbadd commit a5eebd7

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

system/Entity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ protected function mutateDate($value)
421421

422422
protected function castAs($value, string $type)
423423
{
424+
if(substr($type,0,1) === '?' && $value === null) return null;
425+
424426
switch($type)
425427
{
426428
case 'integer':

0 commit comments

Comments
 (0)