Skip to content

Commit 943cf77

Browse files
authored
Add Stringable interface support in Validator.php
1 parent 2a7ce4d commit 943cf77

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/Forms/Validator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Nette;
1313
use Nette\Utils\Strings;
1414
use Nette\Utils\Validators;
15+
use Stringable;
1516
use function array_map, count, explode, in_array, is_array, is_float, is_int, is_object, is_string, preg_replace, preg_replace_callback, rtrim, str_replace, strtolower;
1617
use const UPLOAD_ERR_INI_SIZE;
1718

@@ -58,6 +59,9 @@ public static function formatMessage(Rule $rule, bool $withValue = true): string
5859
if ($message instanceof Nette\HtmlStringable) {
5960
return $message;
6061

62+
} elseif ($message instanceof Stringable) {
63+
return (string)$message;
64+
6165
} elseif ($message === null && is_string($rule->validator) && isset(static::$messages[$rule->validator])) {
6266
$message = static::$messages[$rule->validator];
6367

0 commit comments

Comments
 (0)