v1.2.2
This commit is contained in:
parent
3a25585090
commit
80a2202d6e
18 changed files with 305 additions and 122 deletions
12
vendor/nette/schema/src/Schema/Message.php
vendored
12
vendor/nette/schema/src/Schema/Message.php
vendored
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue