Skip to content

Commit 9b58ad8

Browse files
committed
Rename '__root__' to '__root'
1 parent d719129 commit 9b58ad8

37 files changed

+162
-162
lines changed

docs/03-handling-exceptions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The code above generates the following output:
4444
```no-highlight
4545
Array
4646
(
47-
[__root__] => All the required rules must pass for "The Respect Panda"
47+
[__root] => All the required rules must pass for "The Respect Panda"
4848
[alnum] => "The Respect Panda" must contain only letters (a-z) and digits (0-9)
4949
[lowercase] => "The Respect Panda" must contain only lowercase letters
5050
)
@@ -69,7 +69,7 @@ try {
6969
->assert(
7070
'The Respect Panda',
7171
[
72-
'__root__' => 'The given input is not valid',
72+
'__root' => 'The given input is not valid',
7373
'alnum' => 'Your username must contain only letters and digits',
7474
'lowercase' => 'Your username must be lowercase',
7575
]
@@ -84,7 +84,7 @@ The code above will generate the following output.
8484
```no-highlight
8585
Array
8686
(
87-
[__root__] => The given input is not valid
87+
[__root] => The given input is not valid
8888
[alnum] => Your username must contain only letters and digits
8989
[lowercase] => Your username must be lowercase
9090
)
@@ -100,7 +100,7 @@ use Respect\Validation\Validator as v;
100100

101101
$validator = v::alnum()->lowercase();
102102
$validator->setTemplates([
103-
'__root__' => '{{name}} is not valid',
103+
'__root' => '{{name}} is not valid',
104104
'alnum' => 'Usernames must contain only letters and digits',
105105
'lowercase' => 'Usernames must be lowercase',
106106
]);

library/Message/StandardFormatter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function array(Result $result, array $templates, Translator $translator):
9999
{
100100
$selectedTemplates = $this->selectTemplates($result, $templates);
101101
$messages = [
102-
'__root__' => $this->renderer->render($this->getTemplated($result, $selectedTemplates), $translator),
102+
'__root' => $this->renderer->render($this->getTemplated($result, $selectedTemplates), $translator),
103103
];
104104

105105
$children = [];
@@ -120,7 +120,7 @@ public function array(Result $result, array $templates, Translator $translator):
120120
}
121121

122122
if (count($children) === 0 || $this->isFinalTemplate($result, $selectedTemplates)) {
123-
return [$result->path ?? $result->id => $messages['__root__']];
123+
return [$result->path ?? $result->id => $messages['__root']];
124124
}
125125

126126
if ($result->path !== null) {
@@ -172,7 +172,7 @@ private function getTemplated(Result $result, array $templates): Result
172172
return $result;
173173
}
174174

175-
foreach ([$result->path, $result->name, $result->id, '__root__'] as $key) {
175+
foreach ([$result->path, $result->name, $result->id, '__root'] as $key) {
176176
if (!isset($templates[$key])) {
177177
continue;
178178
}
@@ -211,7 +211,7 @@ private function isFinalTemplate(Result $result, array $templates): bool
211211
}
212212
}
213213

214-
return isset($templates['__root__']);
214+
return isset($templates['__root']);
215215
}
216216

217217
/**

library/Validator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public function assert(mixed $input, array|string|Throwable|callable|null $templ
8181
if (is_array($template)) {
8282
$templates = $template;
8383
} elseif (is_string($template)) {
84-
$templates = ['__root__' => $template];
84+
$templates = ['__root' => $template];
8585
} elseif ($this->getTemplate() != null) {
86-
$templates = ['__root__' => $this->getTemplate()];
86+
$templates = ['__root' => $this->getTemplate()];
8787
}
8888

8989
$exception = new ValidationException(

tests/feature/GetMessagesShouldIncludeAllValidationMessagesInAChainTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function (): void {
2020
->assert(['username' => 'u', 'birthdate' => 'Not a date', 'password' => '']);
2121
},
2222
[
23-
'__root__' => 'All the required rules must pass for `["username": "u", "birthdate": "Not a date", "password": ""]`',
23+
'__root' => 'All the required rules must pass for `["username": "u", "birthdate": "Not a date", "password": ""]`',
2424
'username' => 'The length of username must be between 2 and 32',
2525
'birthdate' => 'birthdate must be a valid date/time',
2626
'password' => 'password must not be empty',

tests/feature/GetMessagesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
->key('schema', v::stringType()))
2121
->assert(['mysql' => ['host' => 42, 'schema' => 42], 'postgresql' => ['user' => 42, 'password' => 42]]),
2222
[
23-
'__root__' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
23+
'__root' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
2424
'mysql' => [
25-
'__root__' => 'All the required rules must pass for mysql',
25+
'__root' => 'All the required rules must pass for mysql',
2626
'host' => 'host must be a string',
2727
'user' => 'user must be present',
2828
'password' => 'password must be present',
2929
'schema' => 'schema must be a string',
3030
],
3131
'postgresql' => [
32-
'__root__' => 'All the required rules must pass for postgresql',
32+
'__root' => 'All the required rules must pass for postgresql',
3333
'host' => 'host must be present',
3434
'user' => 'user must be a string',
3535
'password' => 'password must be a string',

tests/feature/GetMessagesWithReplacementsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ function (): void {
4949
);
5050
},
5151
[
52-
'__root__' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
52+
'__root' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
5353
'mysql' => [
54-
'__root__' => 'All the required rules must pass for mysql',
54+
'__root' => 'All the required rules must pass for mysql',
5555
'host' => '`host` should be a MySQL host',
5656
'user' => 'Value should be a MySQL username',
5757
'password' => 'password must be present',
5858
'schema' => 'schema must be a string',
5959
],
6060
'postgresql' => [
61-
'__root__' => 'All the required rules must pass for postgresql',
61+
'__root' => 'All the required rules must pass for postgresql',
6262
'host' => 'host must be present',
6363
'user' => 'user must be a string',
6464
'password' => 'password must be a string',

tests/feature/Issues/Issue1033Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- "B" must be equal to 1
1818
FULL_MESSAGE,
1919
[
20-
'__root__' => 'Each item in `["A", "B", "B"]` must be valid',
20+
'__root' => 'Each item in `["A", "B", "B"]` must be valid',
2121
0 => '"A" must be equal to 1',
2222
1 => '"B" must be equal to 1',
2323
2 => '"B" must be equal to 1',

tests/feature/Issues/Issue1289Test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
- description must be a string value
5555
FULL_MESSAGE,
5656
[
57-
'__root__' => 'Each item in `[["default": 2, "description": [], "children": ["nope"]]]` must be valid',
57+
'__root' => 'Each item in `[["default": 2, "description": [], "children": ["nope"]]]` must be valid',
5858
0 => [
59-
'__root__' => 'These rules must pass for `["default": 2, "description": [], "children": ["nope"]]`',
59+
'__root' => 'These rules must pass for `["default": 2, "description": [], "children": ["nope"]]`',
6060
'default' => [
61-
'__root__' => 'Only one of these rules must pass for default',
61+
'__root' => 'Only one of these rules must pass for default',
6262
'stringType' => 'default must be a string',
6363
'boolType' => 'default must be a boolean',
6464
],

tests/feature/Issues/Issue1333Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
- User Email must be a valid email address
1717
FULL_MESSAGE,
1818
[
19-
'__root__' => 'All the required rules must pass for User Email',
19+
'__root' => 'All the required rules must pass for User Email',
2020
'noWhitespace' => 'User Email must not contain whitespaces',
2121
'email' => 'User Email must be a valid email address',
2222
]

tests/feature/Issues/Issue1334Test.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@ function (): void {
3535
- street must be a string
3636
FULL_MESSAGE,
3737
[
38-
'__root__' => 'These rules must pass for `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]`',
38+
'__root' => 'These rules must pass for `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]`',
3939
'each' => [
40-
'__root__' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid',
40+
'__root' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid',
4141
0 => [
42-
'__root__' => 'These rules must pass for `["region": "Oregon", "country": "USA", "other": 123]`',
42+
'__root' => 'These rules must pass for `["region": "Oregon", "country": "USA", "other": 123]`',
4343
'street' => 'street must be present',
4444
'other' => [
45-
'__root__' => 'These rules must pass for other',
45+
'__root' => 'These rules must pass for other',
4646
'nullOrStringType' => 'other must be a string or must be null',
4747
],
4848
],
4949
1 => [
50-
'__root__' => 'These rules must pass for `["street": "", "region": "Oregon", "country": "USA"]`',
50+
'__root' => 'These rules must pass for `["street": "", "region": "Oregon", "country": "USA"]`',
5151
'street' => [
52-
'__root__' => 'These rules must pass for street',
52+
'__root' => 'These rules must pass for street',
5353
'notEmpty' => 'street must not be empty',
5454
],
5555
],
5656
2 => [
57-
'__root__' => 'These rules must pass for `["street": 123, "region": "Oregon", "country": "USA"]`',
57+
'__root' => 'These rules must pass for `["street": 123, "region": "Oregon", "country": "USA"]`',
5858
'street' => [
59-
'__root__' => 'These rules must pass for street',
59+
'__root' => 'These rules must pass for street',
6060
'stringType' => 'street must be a string',
6161
],
6262
],

0 commit comments

Comments
 (0)