From 22cec2965142142f1ba24df39a0c420c14253229 Mon Sep 17 00:00:00 2001 From: wfuren <593374099@qq.com> Date: Fri, 20 Apr 2018 09:30:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BD=93=E7=B1=BB=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E4=B8=8D=E6=94=AF=E6=8C=81=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=BAstring=E7=84=B6=E5=90=8ENULL=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E6=9F=A5=E8=AF=A2=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E7=BC=BA=E5=A4=B1=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Helper/EntityHelper.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Helper/EntityHelper.php b/src/Helper/EntityHelper.php index cded85d..24fdab5 100644 --- a/src/Helper/EntityHelper.php +++ b/src/Helper/EntityHelper.php @@ -55,8 +55,12 @@ public static function arrayToEntity(array $data, string $className) } $field = $entities[$className]['column'][$col]; - $setterMethod = 'set' . ucfirst($field); - + $function = explode('_', $field); + $function = array_map(function ($word) { + return ucfirst($word); + }, $function); + $setterMethod = 'set' . implode('', $function); + $type = $entities[$className]['field'][$field]['type']; $value = self::trasferTypes($type, $value); @@ -83,7 +87,7 @@ public static function trasferTypes($type, $value) if ($type === Types::INT || $type === Types::NUMBER) { $value = (int)$value; } elseif ($type === Types::STRING) { - $value = (string)$value; + $value = is_null($value) ? (unset)$value : (string)$value; } elseif ($type === Types::BOOLEAN) { $value = (bool)$value; } elseif ($type === Types::FLOAT) {