From fa65f276e23e5c7010696dbfc5afbecd2804bfd4 Mon Sep 17 00:00:00 2001 From: yurenzhen Date: Wed, 15 May 2019 11:14:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=93=20user=5Fid=20?= =?UTF-8?q?=E4=B8=BA=20string=20=E7=B1=BB=E5=9E=8B(=E5=A6=82uuid)=E6=97=B6?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF=E8=80=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=20updated=5Fby=20=E5=92=8C=20created=5Fby=20=E4=B8=8D?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Someline/Base/Models/BaseModel.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Someline/Base/Models/BaseModel.php b/src/Someline/Base/Models/BaseModel.php index a1357c8..509f359 100644 --- a/src/Someline/Base/Models/BaseModel.php +++ b/src/Someline/Base/Models/BaseModel.php @@ -135,6 +135,21 @@ protected function updateIps() } } + /** + * check the $user_id is valid. + * + * @param int|string $user_id + * @return bool + */ + protected function validUserId($user_id): bool + { + if ('int' === $this->keyType) + return $user_id > 0; + + if ('string' === $this->keyType) + return strlen($user_id) > 0; + } + /** * Update the creation and update by users. * @@ -143,7 +158,7 @@ protected function updateIps() protected function updateUsers() { $user_id = $this->getAuthUserId(); - if (!($user_id > 0)) { + if (!$this->validUserId($user_id)) { return; } @@ -159,7 +174,7 @@ protected function updateUsers() /** * @return bool */ - public function isAuthUserOwner() + public function isAuthUserOwner(): bool { return $this->getAuthUserId() == $this->getUserId(); }