PluginProbe
Packeta / 1.6.1
Packeta v1.6.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / deps / nette / schema / src / Schema / Message.php

Message.php in Packeta 1.6.1, at deps/nette/schema/src/Schema/Message.php

57 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the Nette Framework (https://nette.org)
5 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6 */
7 declare (strict_types=1);
8 namespace Packetery\Nette\Schema;
9
10 use Packetery\Nette;
11 final class Message
12 {
13 use \Packetery\Nette\SmartObject;
14 /** variables: {value: mixed, expected: string} */
15 public const TYPE_MISMATCH = 'schema.typeMismatch';
16 /** variables: {value: mixed, expected: string} */
17 public const VALUE_OUT_OF_RANGE = 'schema.valueOutOfRange';
18 /** variables: {value: mixed, length: int, expected: string} */
19 public const LENGTH_OUT_OF_RANGE = 'schema.lengthOutOfRange';
20 /** variables: {value: string, pattern: string} */
21 public const PATTERN_MISMATCH = 'schema.patternMismatch';
22 /** variables: {value: mixed, assertion: string} */
23 public const FAILED_ASSERTION = 'schema.failedAssertion';
24 /** no variables */
25 public const MISSING_ITEM = 'schema.missingItem';
26 /** variables: {hint: string} */
27 public const UNEXPECTED_ITEM = 'schema.unexpectedItem';
28 /** no variables */
29 public const DEPRECATED = 'schema.deprecated';
30 /** @var string */
31 public $message;
32 /** @var string */
33 public $code;
34 /** @var string[] */
35 public $path;
36 /** @var string[] */
37 public $variables;
38 public function __construct(string $message, string $code, array $path, array $variables = [])
39 {
40 $this->message = $message;
41 $this->code = $code;
42 $this->path = $path;
43 $this->variables = $variables;
44 }
45 public function toString() : string
46 {
47 $vars = $this->variables;
48 $vars['label'] = empty($vars['isKey']) ? 'item' : 'key of item';
49 $vars['path'] = $this->path ? "'" . \implode(" › ", $this->path) . "'" : null;
50 $vars['value'] = Helpers::formatValue($vars['value'] ?? null);
51 return \preg_replace_callback('~( ?)%(\\w+)%~', function ($m) use($vars) {
52 [, $space, $key] = $m;
53 return $vars[$key] === null ? '' : $space . $vars[$key];
54 }, $this->message);
55 }
56 }
57