From cf1bc96e289894f132b7e43def5bff70faa83931 Mon Sep 17 00:00:00 2001 From: Kids Return Date: Mon, 23 Aug 2021 15:38:19 +0800 Subject: [PATCH] Fixed type error when using `Hyperf\Validation\Rules\Unique::__toString()` in PHP8. (#3969) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 李铭昕 <715557344@qq.com> --- CHANGELOG-2.2.md | 4 ++++ src/validation/src/Rules/DatabaseRule.php | 2 +- src/validation/tests/Cases/ValidationUniqueRuleTest.php | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-2.2.md b/CHANGELOG-2.2.md index e81227923..7f468803b 100644 --- a/CHANGELOG-2.2.md +++ b/CHANGELOG-2.2.md @@ -1,5 +1,9 @@ # v2.2.6 - TBD +## Fixed + +- [#3969](https://github.com/hyperf/hyperf/pull/3969) Fixed type error when using `Hyperf\Validation\Rules\Unique::__toString()` in PHP8. + # v2.2.5 - 2021-08-23 ## Fixed diff --git a/src/validation/src/Rules/DatabaseRule.php b/src/validation/src/Rules/DatabaseRule.php index 384c3e802..3f1ef3948 100755 --- a/src/validation/src/Rules/DatabaseRule.php +++ b/src/validation/src/Rules/DatabaseRule.php @@ -159,7 +159,7 @@ trait DatabaseRule protected function formatWheres(): string { return collect($this->wheres)->map(function ($where) { - return $where['column'] . ',' . '"' . str_replace('"', '""', $where['value']) . '"'; + return $where['column'] . ',' . '"' . str_replace('"', '""', (string) $where['value']) . '"'; })->implode(','); } } diff --git a/src/validation/tests/Cases/ValidationUniqueRuleTest.php b/src/validation/tests/Cases/ValidationUniqueRuleTest.php index 3ca7c0133..7c95c401a 100644 --- a/src/validation/tests/Cases/ValidationUniqueRuleTest.php +++ b/src/validation/tests/Cases/ValidationUniqueRuleTest.php @@ -59,6 +59,10 @@ class ValidationUniqueRuleTest extends TestCase $rule = new Unique('table'); $rule->where('foo', '"bar"'); $this->assertEquals('unique:table,NULL,NULL,id,foo,"""bar"""', (string) $rule); + + $rule = new Unique('table'); + $rule->where('foo', 1); + $this->assertEquals('unique:table,NULL,NULL,id,foo,"1"', (string) $rule); } }