From 1d96096f3dff0cabdba5f7588fdc1b864d406181 Mon Sep 17 00:00:00 2001 From: twosee Date: Wed, 17 Jul 2019 17:41:02 +0800 Subject: [PATCH] Add maxStringLength --- src/Assert.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Assert.php b/src/Assert.php index 1d175bb7..bebde6ca 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -190,6 +190,7 @@ class Assert { protected static $throwException = true; + protected static $maxStringLength = 1024; public static function setThrowException(bool $b) { @@ -1332,7 +1333,11 @@ protected static function valueToString($value): string } if (is_string($value)) { - return 'string(' . strlen($value) . ') "' . $value . '"'; + $length = strlen($value); + if ($length > static::$maxStringLength) { + $value = substr($value, 0, static::$maxStringLength) . '...'; + } + return 'string(' . $length . ') "' . $value . '"'; } return (string)$value;