Skip to content

Commit

Permalink
Rename '__root__' to '__root'
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoody committed Dec 21, 2024
1 parent d719129 commit 9b58ad8
Show file tree
Hide file tree
Showing 37 changed files with 162 additions and 162 deletions.
8 changes: 4 additions & 4 deletions docs/03-handling-exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The code above generates the following output:
```no-highlight
Array
(
[__root__] => All the required rules must pass for "The Respect Panda"
[__root] => All the required rules must pass for "The Respect Panda"
[alnum] => "The Respect Panda" must contain only letters (a-z) and digits (0-9)
[lowercase] => "The Respect Panda" must contain only lowercase letters
)
Expand All @@ -69,7 +69,7 @@ try {
->assert(
'The Respect Panda',
[
'__root__' => 'The given input is not valid',
'__root' => 'The given input is not valid',
'alnum' => 'Your username must contain only letters and digits',
'lowercase' => 'Your username must be lowercase',
]
Expand All @@ -84,7 +84,7 @@ The code above will generate the following output.
```no-highlight
Array
(
[__root__] => The given input is not valid
[__root] => The given input is not valid
[alnum] => Your username must contain only letters and digits
[lowercase] => Your username must be lowercase
)
Expand All @@ -100,7 +100,7 @@ use Respect\Validation\Validator as v;

$validator = v::alnum()->lowercase();
$validator->setTemplates([
'__root__' => '{{name}} is not valid',
'__root' => '{{name}} is not valid',
'alnum' => 'Usernames must contain only letters and digits',
'lowercase' => 'Usernames must be lowercase',
]);
Expand Down
8 changes: 4 additions & 4 deletions library/Message/StandardFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function array(Result $result, array $templates, Translator $translator):
{
$selectedTemplates = $this->selectTemplates($result, $templates);
$messages = [
'__root__' => $this->renderer->render($this->getTemplated($result, $selectedTemplates), $translator),
'__root' => $this->renderer->render($this->getTemplated($result, $selectedTemplates), $translator),
];

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

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

if ($result->path !== null) {
Expand Down Expand Up @@ -172,7 +172,7 @@ private function getTemplated(Result $result, array $templates): Result
return $result;
}

foreach ([$result->path, $result->name, $result->id, '__root__'] as $key) {
foreach ([$result->path, $result->name, $result->id, '__root'] as $key) {
if (!isset($templates[$key])) {
continue;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ private function isFinalTemplate(Result $result, array $templates): bool
}
}

return isset($templates['__root__']);
return isset($templates['__root']);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions library/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public function assert(mixed $input, array|string|Throwable|callable|null $templ
if (is_array($template)) {
$templates = $template;
} elseif (is_string($template)) {
$templates = ['__root__' => $template];
$templates = ['__root' => $template];
} elseif ($this->getTemplate() != null) {
$templates = ['__root__' => $this->getTemplate()];
$templates = ['__root' => $this->getTemplate()];
}

$exception = new ValidationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function (): void {
->assert(['username' => 'u', 'birthdate' => 'Not a date', 'password' => '']);
},
[
'__root__' => 'All the required rules must pass for `["username": "u", "birthdate": "Not a date", "password": ""]`',
'__root' => 'All the required rules must pass for `["username": "u", "birthdate": "Not a date", "password": ""]`',
'username' => 'The length of username must be between 2 and 32',
'birthdate' => 'birthdate must be a valid date/time',
'password' => 'password must not be empty',
Expand Down
6 changes: 3 additions & 3 deletions tests/feature/GetMessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
->key('schema', v::stringType()))
->assert(['mysql' => ['host' => 42, 'schema' => 42], 'postgresql' => ['user' => 42, 'password' => 42]]),
[
'__root__' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
'__root' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
'mysql' => [
'__root__' => 'All the required rules must pass for mysql',
'__root' => 'All the required rules must pass for mysql',
'host' => 'host must be a string',
'user' => 'user must be present',
'password' => 'password must be present',
'schema' => 'schema must be a string',
],
'postgresql' => [
'__root__' => 'All the required rules must pass for postgresql',
'__root' => 'All the required rules must pass for postgresql',
'host' => 'host must be present',
'user' => 'user must be a string',
'password' => 'password must be a string',
Expand Down
6 changes: 3 additions & 3 deletions tests/feature/GetMessagesWithReplacementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ function (): void {
);
},
[
'__root__' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
'__root' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
'mysql' => [
'__root__' => 'All the required rules must pass for mysql',
'__root' => 'All the required rules must pass for mysql',
'host' => '`host` should be a MySQL host',
'user' => 'Value should be a MySQL username',
'password' => 'password must be present',
'schema' => 'schema must be a string',
],
'postgresql' => [
'__root__' => 'All the required rules must pass for postgresql',
'__root' => 'All the required rules must pass for postgresql',
'host' => 'host must be present',
'user' => 'user must be a string',
'password' => 'password must be a string',
Expand Down
2 changes: 1 addition & 1 deletion tests/feature/Issues/Issue1033Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- "B" must be equal to 1
FULL_MESSAGE,
[
'__root__' => 'Each item in `["A", "B", "B"]` must be valid',
'__root' => 'Each item in `["A", "B", "B"]` must be valid',
0 => '"A" must be equal to 1',
1 => '"B" must be equal to 1',
2 => '"B" must be equal to 1',
Expand Down
6 changes: 3 additions & 3 deletions tests/feature/Issues/Issue1289Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
- description must be a string value
FULL_MESSAGE,
[
'__root__' => 'Each item in `[["default": 2, "description": [], "children": ["nope"]]]` must be valid',
'__root' => 'Each item in `[["default": 2, "description": [], "children": ["nope"]]]` must be valid',
0 => [
'__root__' => 'These rules must pass for `["default": 2, "description": [], "children": ["nope"]]`',
'__root' => 'These rules must pass for `["default": 2, "description": [], "children": ["nope"]]`',
'default' => [
'__root__' => 'Only one of these rules must pass for default',
'__root' => 'Only one of these rules must pass for default',
'stringType' => 'default must be a string',
'boolType' => 'default must be a boolean',
],
Expand Down
2 changes: 1 addition & 1 deletion tests/feature/Issues/Issue1333Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- User Email must be a valid email address
FULL_MESSAGE,
[
'__root__' => 'All the required rules must pass for User Email',
'__root' => 'All the required rules must pass for User Email',
'noWhitespace' => 'User Email must not contain whitespaces',
'email' => 'User Email must be a valid email address',
]
Expand Down
16 changes: 8 additions & 8 deletions tests/feature/Issues/Issue1334Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ function (): void {
- street must be a string
FULL_MESSAGE,
[
'__root__' => 'These rules must pass for `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]`',
'__root' => 'These rules must pass for `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]`',
'each' => [
'__root__' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid',
'__root' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid',
0 => [
'__root__' => 'These rules must pass for `["region": "Oregon", "country": "USA", "other": 123]`',
'__root' => 'These rules must pass for `["region": "Oregon", "country": "USA", "other": 123]`',
'street' => 'street must be present',
'other' => [
'__root__' => 'These rules must pass for other',
'__root' => 'These rules must pass for other',
'nullOrStringType' => 'other must be a string or must be null',
],
],
1 => [
'__root__' => 'These rules must pass for `["street": "", "region": "Oregon", "country": "USA"]`',
'__root' => 'These rules must pass for `["street": "", "region": "Oregon", "country": "USA"]`',
'street' => [
'__root__' => 'These rules must pass for street',
'__root' => 'These rules must pass for street',
'notEmpty' => 'street must not be empty',
],
],
2 => [
'__root__' => 'These rules must pass for `["street": 123, "region": "Oregon", "country": "USA"]`',
'__root' => 'These rules must pass for `["street": 123, "region": "Oregon", "country": "USA"]`',
'street' => [
'__root__' => 'These rules must pass for street',
'__root' => 'These rules must pass for street',
'stringType' => 'street must be a string',
],
],
Expand Down
20 changes: 10 additions & 10 deletions tests/feature/Issues/Issue1348Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,39 @@
- model must be in `["F150", "Bronco"]`
FULL_MESSAGE,
[
'__root__' => 'These rules must pass for `[["manufacturer": "Honda", "model": "Accord"], ["manufacturer": "Toyota", "model": "Rav4"], ["manufacturer": "Fo ... ]`',
'__root' => 'These rules must pass for `[["manufacturer": "Honda", "model": "Accord"], ["manufacturer": "Toyota", "model": "Rav4"], ["manufacturer": "Fo ... ]`',
'each' => [
'__root__' => 'Each item in `[["manufacturer": "Honda", "model": "Accord"], ["manufacturer": "Toyota", "model": "Rav4"], ["manufacturer": "Fo ... ]` must be valid',
'__root' => 'Each item in `[["manufacturer": "Honda", "model": "Accord"], ["manufacturer": "Toyota", "model": "Rav4"], ["manufacturer": "Fo ... ]` must be valid',
2 => [
'__root__' => 'Only one of these rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'__root' => 'Only one of these rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'allOf.1' => [
'__root__' => 'All the required rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'__root' => 'All the required rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'manufacturer' => 'manufacturer must be equal to "Honda"',
'model' => 'model must be in `["Accord", "Fit"]`',
],
'allOf.2' => [
'__root__' => 'All the required rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'__root' => 'All the required rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'manufacturer' => 'manufacturer must be equal to "Toyota"',
'model' => 'model must be in `["Rav4", "Camry"]`',
],
'allOf.3' => [
'__root__' => 'These rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'__root' => 'These rules must pass for `["manufacturer": "Ford", "model": "not real"]`',
'model' => 'model must be in `["F150", "Bronco"]`',
],
],
3 => [
'__root__' => 'Only one of these rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'__root' => 'Only one of these rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'allOf.1' => [
'__root__' => 'These rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'__root' => 'These rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'model' => 'model must be in `["Accord", "Fit"]`',
],
'allOf.2' => [
'__root__' => 'All the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'__root' => 'All the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'manufacturer' => 'manufacturer must be equal to "Toyota"',
'model' => 'model must be in `["Rav4", "Camry"]`',
],
'allOf.3' => [
'__root__' => 'All the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'__root' => 'All the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]`',
'manufacturer' => 'manufacturer must be equal to "Ford"',
'model' => 'model must be in `["F150", "Bronco"]`',
],
Expand Down
4 changes: 2 additions & 2 deletions tests/feature/Issues/Issue1376Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
- user must be present
FULL_MESSAGE,
[
'__root__' => 'All the required rules must pass for `stdClass { +$author="foo" }`',
'__root' => 'All the required rules must pass for `stdClass { +$author="foo" }`',
'title' => 'title must be present',
'description' => 'description must be present',
'author' => [
'__root__' => 'All the required rules must pass for author',
'__root' => 'All the required rules must pass for author',
'intType' => 'author must be an integer',
'lengthBetween' => 'The length of author must be between 1 and 2',
],
Expand Down
12 changes: 6 additions & 6 deletions tests/feature/Issues/Issue1427Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@
- permissions must be iterable
FULL_MESSAGE,
[
'__root__' => 'Each item in `[16: ["groups": [1, "A", 3, 4, 5], "permissions": ["perm1": true, "perm2": false, "perm3": "boom!"]], 18: false, ... ]` must be valid',
'__root' => 'Each item in `[16: ["groups": [1, "A", 3, 4, 5], "permissions": ["perm1": true, "perm2": false, "perm3": "boom!"]], 18: false, ... ]` must be valid',
16 => [
'__root__' => 'These rules must pass for `["groups": [1, "A", 3, 4, 5], "permissions": ["perm1": true, "perm2": false, "perm3": "boom!"]]`',
'__root' => 'These rules must pass for `["groups": [1, "A", 3, 4, 5], "permissions": ["perm1": true, "perm2": false, "perm3": "boom!"]]`',
'groups' => [
'__root__' => 'Each item in groups must be valid',
'__root' => 'Each item in groups must be valid',
1 => 'groups must be an integer value',
],
'permissions' => [
'__root__' => 'Each item in permissions must be valid',
'__root' => 'Each item in permissions must be valid',
'perm3' => 'permissions must be a boolean value',
],
],
18 => [
'__root__' => 'All the required rules must pass for `false`',
'__root' => 'All the required rules must pass for `false`',
'arrayVal' => '`false` must be an array value',
'groups' => 'groups must be present',
'permissions' => 'permissions must be present',
],
24 => [
'__root__' => 'These rules must pass for `["permissions": false]`',
'__root' => 'These rules must pass for `["permissions": false]`',
'groups' => 'groups must be present',
'permissions' => 'permissions must be iterable',
],
Expand Down
12 changes: 6 additions & 6 deletions tests/feature/Issues/Issue1469Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ function (): void {
- product_title2 must not be present
FULL_MESSAGE,
[
'__root__' => 'These rules must pass for `["order_items": [["product_title": test(?string $description = null, ?Closure $closure = null): Pest\Support\Hig ... ]`',
'__root' => 'These rules must pass for `["order_items": [["product_title": test(?string $description = null, ?Closure $closure = null): Pest\Support\Hig ... ]`',
'keySet' => [
'__root__' => '`["order_items": [["product_title": test(?string $description = null, ?Closure $closure = null): Pest\Support\Hig ... ]` validation failed',
'__root' => '`["order_items": [["product_title": test(?string $description = null, ?Closure $closure = null): Pest\Support\Hig ... ]` validation failed',
'each' => [
'__root__' => 'Each item in order_items must be valid',
'__root' => 'Each item in order_items must be valid',
0 => [
'__root__' => 'order_items validation failed',
'__root' => 'order_items validation failed',
'quantity' => [
'__root__' => 'These rules must pass for quantity',
'__root' => 'These rules must pass for quantity',
'intVal' => 'quantity must be an integer value',
],
],
1 => [
'__root__' => 'order_items contains both missing and extra keys',
'__root' => 'order_items contains both missing and extra keys',
'product_title' => 'product_title must be present',
'quantity' => 'quantity must be present',
'product_title2' => 'product_title2 must not be present',
Expand Down
2 changes: 1 addition & 1 deletion tests/feature/Issues/Issue179Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function (): void {
- user must be present
FULL_MESSAGE,
[
'__root__' => 'These rules must pass for Settings',
'__root' => 'These rules must pass for Settings',
'host' => 'host must be a string',
'user' => 'user must be present',
]
Expand Down
2 changes: 1 addition & 1 deletion tests/feature/Issues/Issue425Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function (): void {
'reference must be present',
'- reference must be present',
[
'__root__' => 'These rules must pass for `["age": 1]`',
'__root' => 'These rules must pass for `["age": 1]`',
'reference' => 'reference must be present',
]
));
2 changes: 1 addition & 1 deletion tests/feature/Issues/Issue446Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'The length of name must be between 2 and 32',
'- The length of name must be between 2 and 32',
[
'__root__' => 'These rules must pass for `["name": "w", "email": "[email protected]"]`',
'__root' => 'These rules must pass for `["name": "w", "email": "[email protected]"]`',
'name' => 'The length of name must be between 2 and 32',
]
));
6 changes: 3 additions & 3 deletions tests/feature/Issues/Issue796Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
- user must be a string
FULL_MESSAGE,
[
'__root__' => 'All the required rules must pass for the given data',
'__root' => 'All the required rules must pass for the given data',
'mysql' => [
'__root__' => 'These rules must pass for mysql',
'__root' => 'These rules must pass for mysql',
'host' => 'host must be a string',
],
'postgresql' => [
'__root__' => 'These rules must pass for postgresql',
'__root' => 'These rules must pass for postgresql',
'user' => 'user must be a string',
],
]
Expand Down
Loading

0 comments on commit 9b58ad8

Please sign in to comment.