This commit is contained in:
Javier Casares 2026-08-24 11:42:10 +00:00
commit 80a2202d6e
18 changed files with 305 additions and 122 deletions

View file

@ -7,9 +7,12 @@
namespace Nette\Schema;
use function implode, preg_replace_callback;
use function array_key_exists, implode, preg_replace_callback;
/**
* Represents a single validation error or warning with a message template, error code, path, and variables.
*/
final class Message
{
/** variables: {value: mixed, expected: string} */
@ -72,6 +75,9 @@ final class Message
}
/**
* Formats the message template by substituting %variable% placeholders with their values.
*/
public function toString(): string
{
$vars = $this->variables;
@ -83,7 +89,9 @@ final class Message
return preg_replace_callback('~( ?)%(\w+)%~', function ($m) use ($vars) {
[, $space, $key] = $m;
return $vars[$key] === null ? '' : $space . $vars[$key];
return array_key_exists($key, $vars)
? ($vars[$key] === null ? '' : $space . $vars[$key])
: $m[0];
}, $this->message);
}
}