Skip to content

Commit 4840527

Browse files
committed
Replace placeholder "name" with "subject"
The `{{name}}` placeholder could represent different things depending on the state of the Result, and referring to it as `{{name}}` seems arbitrary. This commit changes it to `{{subject}}`, which is much more generic and it describes well what that placeholder can mean.
1 parent 8332d28 commit 4840527

File tree

321 files changed

+1874
-1722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

321 files changed

+1874
-1722
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ learn that just by looking at other rules. Pick the simple ones like `ArrayType`
1616
to begin.
1717

1818
Before writing anything, feature or bug fix:
19+
1920
- Check if there is already an issue related to it (opened or closed) and if
2021
someone is already working on that;
21-
- If there is not, [open an issue][] and notify everybody that you're going
22-
to work on that;
23-
- If there is, create a comment to notify everybody that you're going to
24-
work on that.
22+
- If there is not, [open an issue][] and notify everybody that you're going
23+
to work on that;
24+
- If there is, create a comment to notify everybody that you're going to
25+
work on that.
2526
- Make sure that what you need is not done yet
2627

2728
## Adding a new validator
2829

2930
A common validator (rule) on Respect\Validation is composed of three classes:
3031

31-
* `library/Rules/YourRuleName.php`: the rule itself
32-
* `tests/unit/Rules/YourRuleNameTest.php`: tests for the rule
32+
- `library/Rules/YourRuleName.php`: the rule itself
33+
- `tests/unit/Rules/YourRuleNameTest.php`: tests for the rule
3334

3435
The classes are pretty straightforward. In the sample below, we're going to
3536
create a validator that validates if a string is equal to "Hello World".
@@ -65,8 +66,8 @@ use Respect\Validation\Message\Template;
6566
use Respect\Validation\Rules\Core\Simple;
6667

6768
#[Template(
68-
'{{name}} must be a Hello World',
69-
'{{name}} must not be a Hello World',
69+
'{{subject}} must be a Hello World',
70+
'{{subject}} must not be a Hello World',
7071
)]
7172
final class HelloWorld extends Simple
7273
{
@@ -155,6 +156,7 @@ After run `composer install` on the library's root directory you must run PHPUni
155156
### Linux
156157

157158
You can test the project using the commands:
159+
158160
```sh
159161
$ vendor/bin/phpunit
160162
```
@@ -168,6 +170,7 @@ $ composer phpunit
168170
### Windows
169171

170172
You can test the project using the commands:
173+
171174
```sh
172175
> vendor\bin\phpunit
173176
```
@@ -187,5 +190,5 @@ and changing it according to your needs.
187190
[data provider]: https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers "PHPUnit Data Providers"
188191
[open an issue]: http://github.com/Respect/Validation/issues
189192
[PHP-FIG]: http://www.php-fig.org "PHP Framework Interop Group"
190-
[project documentation]: https://respect-validation.readthedocs.io/ "Respect\Validation documentation"
193+
[project documentation]: https://respect-validation.readthedocs.io/ "Respect\\Validation documentation"
191194
[pull requests]: http://help.github.com/pull-requests "GitHub pull requests"

docs/02-feature-guide.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ if (v::intType()->positive()->isValid($input)) {
1919
```
2020

2121
Note that you can combine multiple rules for a complex validation.
22+
2223
## Validating using exceptions
2324

2425
The `assert()` method throws an exception when validation fails. You can handle those exceptions with `try/catch` for more robust error handling.
@@ -33,24 +34,24 @@ v::intType()->positive()->assert($input);
3334

3435
Respect\Validation offers over 150 rules, many of which are designed to address common scenarios. Here’s a quick guide to some specific use cases and the rules that make validation straightforward.
3536

36-
* Using rules as **PHP Attributes**: [Attributes](rules/Attributes.md).
37-
* Validating **Arrays**: [Key](rules/Key.md), [KeyOptional](rules/KeyOptional.md), [KeyExists](rules/KeyExists.md).
38-
* Validating **Array structures**: [KeySet](rules/KeySet.md).
39-
* Validating **Object properties**: [Property](rules/Property.md), [PropertyOptional](rules/PropertyOptional.md), [PropertyExists](rules/PropertyExists.md).
40-
* Using **Conditional validation**: [NullOr](rules/NullOr.md), [UndefOr](rules/UndefOr.md), [When](rules/When.md).
41-
* Using **Grouped validation**: [AllOf](rules/AllOf.md), [AnyOf](rules/AnyOf.md), [NoneOf](rules/NoneOf.md), [OneOf](rules/OneOf.md)
42-
* Validating **Each** value in the input: [Each](rules/Each.md).
43-
* Validating the **Length** of the input: [Length](rules/Length.md).
44-
* Validating the **Maximum** value in the input: [Max](rules/Max.md).
45-
* Validating the **Minimum** value in the input: [Min](rules/Min.md).
46-
* Handling **Special cases**: [Lazy](rules/Lazy.md), [Circuit](rules/Circuit.md), [Call](rules/Call.md).
37+
- Using rules as **PHP Attributes**: [Attributes](rules/Attributes.md).
38+
- Validating **Arrays**: [Key](rules/Key.md), [KeyOptional](rules/KeyOptional.md), [KeyExists](rules/KeyExists.md).
39+
- Validating **Array structures**: [KeySet](rules/KeySet.md).
40+
- Validating **Object properties**: [Property](rules/Property.md), [PropertyOptional](rules/PropertyOptional.md), [PropertyExists](rules/PropertyExists.md).
41+
- Using **Conditional validation**: [NullOr](rules/NullOr.md), [UndefOr](rules/UndefOr.md), [When](rules/When.md).
42+
- Using **Grouped validation**: [AllOf](rules/AllOf.md), [AnyOf](rules/AnyOf.md), [NoneOf](rules/NoneOf.md), [OneOf](rules/OneOf.md)
43+
- Validating **Each** value in the input: [Each](rules/Each.md).
44+
- Validating the **Length** of the input: [Length](rules/Length.md).
45+
- Validating the **Maximum** value in the input: [Max](rules/Max.md).
46+
- Validating the **Minimum** value in the input: [Min](rules/Min.md).
47+
- Handling **Special cases**: [Lazy](rules/Lazy.md), [Circuit](rules/Circuit.md), [Call](rules/Call.md).
4748

4849
### Custom templates
4950

5051
Define your own error message when the validation fails:
5152

5253
```php
53-
v::between(1, 256)->assert($input, '{{name}} is not what I was expecting');
54+
v::between(1, 256)->assert($input, '{{subject}} is not what I was expecting');
5455
```
5556

5657
### Custom templates per rule
@@ -67,6 +68,7 @@ v::alnum()->lowercase()->assert($input, [
6768
### Custom exception objects
6869

6970
Integrate your own exception objects when the validation fails:
71+
7072
```php
7173
v::alnum()->assert($input, new DomainException('Not a valid username'));
7274
```
@@ -87,7 +89,7 @@ v::alnum()->lowercase()->assert(
8789

8890
## Inverting validation rules
8991

90-
Use the `not` prefix to invert a validation rule.
92+
Use the `not` prefix to invert a validation rule.
9193

9294
```php
9395
v::notEquals('main')->assert($input);
@@ -109,7 +111,7 @@ $validator->assert('alexandre gaigalas');
109111

110112
## Customising validator names
111113

112-
Template messages include the placeholder `{{name}}`, which defaults to the input. Use `setName()` to replace it with a more descriptive label.
114+
Template messages include the placeholder `{{subject}}`, which defaults to the input. Use `setName()` to replace it with a more descriptive label.
113115

114116
```php
115117
v::dateTime('Y-m-d')

docs/03-handling-exceptions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Handling exceptions
22

33
The `Validator::assert()` method simplifies exception handling by throwing `ValidationException` exceptions when validation fails. These exceptions provide detailed feedback on what went wrong.
4+
45
## Full exception message
56

67
The `getFullMessage()` method will return a full comprehensive explanation of rules that didn't pass in a nested Markdown list format.
@@ -51,6 +52,7 @@ Array
5152
```
5253

5354
When validating with [Key](rules/Key.md) or [Property](rules/Property.md) the keys of will correspond to the name of the key or property that failed the validation.
55+
5456
## Custom templates
5557

5658
You can tailor the messages to better suit your needs.
@@ -100,7 +102,7 @@ use Respect\Validation\Validator as v;
100102

101103
$validator = v::alnum()->lowercase();
102104
$validator->setTemplates([
103-
'__root__' => '{{name}} is not valid',
105+
'__root__' => '{{subject}} is not valid',
104106
'alnum' => 'Usernames must contain only letters and digits',
105107
'lowercase' => 'Usernames must be lowercase',
106108
]);

docs/05-message-placeholder-conversion.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ to convert them to string.
77
We use the `ParameterStringifier` to convert those parameters into a string.
88
Our default implementation will convert all parameters with
99
[Respect\Stringifier](https://github.com/Respect/Stringifier) unless the
10-
parameter is called `name` and it is already a string.
10+
parameter is called `subject` and it is already a string.
1111

1212
It is possible to overwrite that behavior by creating a custom implementation of
1313
the `ParameterStringifier` and passing it to the `Factory`:

docs/07-custom-rules.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You can also create and use your own rules. To do this, you will need to create
44
a rule and an exception to go with the rule.
55

66
To create a rule, you need to create a class that implements the `Rule` interface
7-
and is within the Rules `namespace`. It is convenient to just extend the `Simple` or
7+
and is within the Rules `namespace`. It is convenient to just extend the `Simple` or
88
`Standard` class. When the rule is called the logic inside the validate method will be
99
executed. Here's how the class should look:
1010

@@ -15,8 +15,8 @@ use Respect\Validation\Message\Template;
1515
use Respect\Validation\Rules\Core\Simple;
1616

1717
#[Template(
18-
'{{name}} is something',
19-
'{{name}} is not something',
18+
'{{subject}} is something',
19+
'{{subject}} is not something',
2020
)]
2121
final class Something extends Simple
2222
{
@@ -27,7 +27,7 @@ final class Something extends Simple
2727
}
2828
```
2929

30-
The `'{{name}} is not something` message would be used then you call the rule
30+
The `'{{subject}} is not something` message would be used then you call the rule
3131
with the `not()`.
3232

3333
All classes in Validation are created by the `Factory` class. If you want

docs/rules/AllOf.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ v::allOf(v::intVal(), v::positive())->isValid(15); // true
1414

1515
Used when some rules must be failed.
1616

17-
| Mode | Template |
18-
|------------|------------------------------|
19-
| `default` | {{name}} must pass the rules |
20-
| `inverted` | {{name}} must pass the rules |
17+
| Mode | Template |
18+
| ---------- | ------------------------------- |
19+
| `default` | {{subject}} must pass the rules |
20+
| `inverted` | {{subject}} must pass the rules |
2121

2222
### `AllOf::TEMPLATE_ALL`
2323

2424
Used when all rules have failed.
2525

26-
| Mode | Template |
27-
|------------|----------------------------------|
28-
| `default` | {{name}} must pass all the rules |
29-
| `inverted` | {{name}} must pass all the rules |
26+
| Mode | Template |
27+
| ---------- | ----------------------------------- |
28+
| `default` | {{subject}} must pass all the rules |
29+
| `inverted` | {{subject}} must pass all the rules |
3030

3131
## Template placeholders
3232

3333
| Placeholder | Description |
34-
|-------------|------------------------------------------------------------------|
35-
| `name` | The validated input or the custom validator name (if specified). |
34+
| ----------- | ---------------------------------------------------------------- |
35+
| `subject` | The validated input or the custom validator name (if specified). |
3636

3737
## Categorization
3838

@@ -42,11 +42,12 @@ Used when all rules have failed.
4242
## Changelog
4343

4444
| Version | Description |
45-
|--------:|-----------------------------------------|
45+
| ------: | --------------------------------------- |
4646
| 3.0.0 | Require at least two rules to be passed |
4747
| 0.3.9 | Created |
4848

49-
***
49+
---
50+
5051
See also:
5152

5253
- [AnyOf](AnyOf.md)

docs/rules/Alnum.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ of extra chars passed as the parameter.
3030

3131
### `Alnum::TEMPLATE_STANDARD`
3232

33-
| Mode | Template |
34-
|------------|-----------------------------------------------------------|
35-
| `default` | {{name}} must contain only letters (a-z) and digits (0-9) |
36-
| `inverted` | {{name}} must not contain letters (a-z) or digits (0-9) |
33+
| Mode | Template |
34+
| ---------- | ------------------------------------------------------------ |
35+
| `default` | {{subject}} must contain only letters (a-z) and digits (0-9) |
36+
| `inverted` | {{subject}} must not contain letters (a-z) or digits (0-9) |
3737

3838
### `Alnum::TEMPLATE_EXTRA`
3939

40-
| Mode | Template |
41-
|------------|---------------------------------------------------------------------------------|
42-
| `default` | {{name}} must contain only letters (a-z), digits (0-9), and {{additionalChars}} |
43-
| `inverted` | {{name}} must not contain letters (a-z), digits (0-9), or {{additionalChars}} |
40+
| Mode | Template |
41+
| ---------- | ---------------------------------------------------------------------------------- |
42+
| `default` | {{subject}} must contain only letters (a-z), digits (0-9), and {{additionalChars}} |
43+
| `inverted` | {{subject}} must not contain letters (a-z), digits (0-9), or {{additionalChars}} |
4444

4545
## Template placeholders
4646

4747
| Placeholder | Description |
48-
|-------------------|------------------------------------------------------------------|
48+
| ----------------- | ---------------------------------------------------------------- |
4949
| `additionalChars` | Additional characters that are considered valid. |
50-
| `name` | The validated input or the custom validator name (if specified). |
50+
| `subject` | The validated input or the custom validator name (if specified). |
5151

5252
## Categorization
5353

@@ -56,11 +56,12 @@ of extra chars passed as the parameter.
5656
## Changelog
5757

5858
| Version | Description |
59-
|--------:|-------------------------------------------|
59+
| ------: | ----------------------------------------- |
6060
| 2.0.0 | Removed support to whitespaces by default |
6161
| 0.3.9 | Created |
6262

63-
***
63+
---
64+
6465
See also:
6566

6667
- [Alpha](Alpha.md)

docs/rules/Alpha.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ v::alpha()->uppercase()->isValid('example'); // false
2525

2626
### `Alpha::TEMPLATE_STANDARD`
2727

28-
| Mode | Template |
29-
|------------|------------------------------------------|
30-
| `default` | {{name}} must contain only letters (a-z) |
31-
| `inverted` | {{name}} must not contain letters (a-z) |
28+
| Mode | Template |
29+
| ---------- | ------------------------------------------- |
30+
| `default` | {{subject}} must contain only letters (a-z) |
31+
| `inverted` | {{subject}} must not contain letters (a-z) |
3232

3333
### `Alpha::TEMPLATE_EXTRA`
3434

35-
| Mode | Template |
36-
|------------|------------------------------------------------------------------|
37-
| `default` | {{name}} must contain only letters (a-z) and {{additionalChars}} |
38-
| `inverted` | {{name}} must not contain letters (a-z) or {{additionalChars}} |
35+
| Mode | Template |
36+
| ---------- | ------------------------------------------------------------------- |
37+
| `default` | {{subject}} must contain only letters (a-z) and {{additionalChars}} |
38+
| `inverted` | {{subject}} must not contain letters (a-z) or {{additionalChars}} |
3939

4040
## Template placeholders
4141

4242
| Placeholder | Description |
43-
|-------------------|------------------------------------------------------------------|
43+
| ----------------- | ---------------------------------------------------------------- |
4444
| `additionalChars` | Additional characters that are considered valid. |
45-
| `name` | The validated input or the custom validator name (if specified). |
45+
| `subject` | The validated input or the custom validator name (if specified). |
4646

4747
## Categorization
4848

@@ -51,11 +51,12 @@ v::alpha()->uppercase()->isValid('example'); // false
5151
## Changelog
5252

5353
| Version | Description |
54-
|--------:|-------------------------------------------|
54+
| ------: | ----------------------------------------- |
5555
| 2.0.0 | Removed support to whitespaces by default |
5656
| 0.3.9 | Created |
5757

58-
***
58+
---
59+
5960
See also:
6061

6162
- [Alnum](Alnum.md)

docs/rules/AlwaysInvalid.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ v::alwaysInvalid()->isValid('whatever'); // false
1212

1313
### `AlwaysInvalid::TEMPLATE_STANDARD`
1414

15-
| Mode | Template |
16-
|------------|--------------------------|
17-
| `default` | {{name}} must be valid |
18-
| `inverted` | {{name}} must be invalid |
15+
| Mode | Template |
16+
| ---------- | --------------------------- |
17+
| `default` | {{subject}} must be valid |
18+
| `inverted` | {{subject}} must be invalid |
1919

2020
### `AlwaysInvalid::TEMPLATE_SIMPLE`
2121

22-
| Mode | Template |
23-
|------------|---------------------|
24-
| `default` | {{name}} is invalid |
25-
| `inverted` | {{name}} is valid |
22+
| Mode | Template |
23+
| ---------- | ---------------------- |
24+
| `default` | {{subject}} is invalid |
25+
| `inverted` | {{subject}} is valid |
2626

2727
## Template placeholders
2828

2929
| Placeholder | Description |
30-
|-------------|------------------------------------------------------------------|
31-
| `name` | The validated input or the custom validator name (if specified). |
30+
| ----------- | ---------------------------------------------------------------- |
31+
| `subject` | The validated input or the custom validator name (if specified). |
3232

3333
## Categorization
3434

@@ -37,10 +37,11 @@ v::alwaysInvalid()->isValid('whatever'); // false
3737
## Changelog
3838

3939
| Version | Description |
40-
|--------:|-------------|
40+
| ------: | ----------- |
4141
| 0.5.0 | Created |
4242

43-
***
43+
---
44+
4445
See also:
4546

4647
- [AlwaysValid](AlwaysValid.md)

0 commit comments

Comments
 (0)