fix: 🐛 开启严格模式,导致mb_strlen函数报类型错误

Closes: #1205
This commit is contained in:
chunhei2008 2019-12-31 15:10:56 +08:00
parent 138bfa9325
commit 77e7789be3
2 changed files with 8 additions and 1 deletions

View File

@ -30,6 +30,7 @@ use Hyperf\Validation\ValidationData;
use InvalidArgumentException; use InvalidArgumentException;
use SplFileInfo; use SplFileInfo;
use Throwable; use Throwable;
use function DI\string;
trait ValidatesAttributes trait ValidatesAttributes
{ {
@ -1492,7 +1493,7 @@ trait ValidatesAttributes
return $value->getSize() / 1024; return $value->getSize() / 1024;
} }
return mb_strlen($value); return mb_strlen((string)$value);
} }
/** /**

View File

@ -1505,6 +1505,12 @@ class ValidationValidatorTest extends TestCase
$v = new Validator($trans, ['foo' => '3'], ['foo' => 'Numeric|Size:3']); $v = new Validator($trans, ['foo' => '3'], ['foo' => 'Numeric|Size:3']);
$this->assertTrue($v->passes()); $this->assertTrue($v->passes());
$v = new Validator($trans, ['foo' => 123], ['foo' => 'Size:123']);
$this->assertFalse($v->passes());
$v = new Validator($trans, ['foo' => 3], ['foo' => 'Size:1']);
$this->assertTrue($v->passes());
$v = new Validator($trans, ['foo' => [1, 2, 3]], ['foo' => 'Array|Size:3']); $v = new Validator($trans, ['foo' => [1, 2, 3]], ['foo' => 'Array|Size:3']);
$this->assertTrue($v->passes()); $this->assertTrue($v->passes());