You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/messages/placeholder-pipes.md
+10-83Lines changed: 10 additions & 83 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,27 +5,12 @@ SPDX-License-Identifier: MIT
5
5
6
6
# Placeholder Pipes
7
7
8
-
Validation uses [Stringifier](https://github.com/Respect/Stringifier) to convert values into strings for templates. By default, strings get double quotes around them. With placeholder pipes, you can customize how values are rendered by adding a pipe (`|`) followed by the modifier name to your placeholder.
8
+
Validation uses [StringFormatter](https://github.com/Respect/StringFormatter) to render validation messages. Placeholder pipes allow you to customize how values are rendered by adding a pipe (`|`) followed by a modifier name to your placeholder.
9
9
10
10
## Usage
11
11
12
12
To use a placeholder pipe, modify your placeholder like this: `{{placeholder|modifier}}`
13
13
14
-
```php
15
-
v::templated(
16
-
'The {{field|raw}} field is required',
17
-
v::notEmpty(),
18
-
['field' => 'email'],
19
-
)->assert('');
20
-
// → The email field is required
21
-
```
22
-
23
-
## Available Modifiers
24
-
25
-
### raw
26
-
27
-
The `raw` modifier removes quotes around values, which is useful for field names or labels that shouldn't look like string values:
28
-
29
14
```php
30
15
v::templated(
31
16
'The {{field|raw}} field is required',
@@ -36,60 +21,11 @@ v::templated(
36
21
// (instead of: The "email" field is required)
37
22
```
38
23
39
-
### quote
40
-
41
-
The `quote` modifier uses backticks instead of double quotes, which is great for patterns or code-like values:
42
-
43
-
```php
44
-
v::templated(
45
-
'Product SKU must follow the {{pattern|quote}} format',
46
-
v::regex('/^[A-Z]{3}-\d{4}$/'),
47
-
['pattern' => 'XXX-0000'],
48
-
)->assert('invalid-sku');
49
-
// → Product SKU must follow the `XXX-0000` format
50
-
```
51
-
52
-
### trans
53
-
54
-
The `trans` modifier translates the value when using a translator:
55
-
56
-
```php
57
-
v::templated(
58
-
'Le champ {{field|trans}} est invalide',
59
-
v::email(),
60
-
['field' => 'email_address'], // key in your translation file
61
-
)->assert('not-an-email');
62
-
// → Le champ "adresse e-mail" est invalide
63
-
```
64
-
65
-
### list:or
66
-
67
-
The `list:or` modifier formats arrays as readable lists using "or":
68
-
69
-
```php
70
-
v::templated(
71
-
'Status must be {{haystack|list:or}}',
72
-
v::in(['active', 'pending', 'archived']),
73
-
)->assert('deleted');
74
-
// → Status must be "active", "pending", or "archived"
75
-
```
76
-
77
-
### list:and
78
-
79
-
The `list:and` modifier formats arrays as readable lists using "and":
80
-
81
-
```php
82
-
v::templated(
83
-
'User must have {{roles|list:and}} roles to perform this action',
// → User must have "admin" and "editor" roles to perform this action
88
-
```
24
+
## Available Modifiers
89
25
90
-
## Combining with Custom Templates
26
+
Validation supports all modifiers from StringFormatter except `StringPassthroughModifier`. For detailed documentation on each modifier, see the [StringFormatter Modifiers documentation](https://github.com/Respect/StringFormatter/blob/main/docs/modifiers/Modifiers.md).
91
27
92
-
Placeholder pipes work with both inline templates and `Templated` validators:
28
+
## Examples
93
29
94
30
```php
95
31
// Using with assert()
@@ -101,20 +37,11 @@ v::templated(
101
37
v::email(),
102
38
['field' => 'email']
103
39
)->assert($input);
104
-
```
105
-
106
-
## Nested Validators
107
40
108
-
Placeholder pipes are particularly useful when working with nested validators:
109
-
110
-
```php
111
-
v::key('age', v::positive())
112
-
->assert($input, [
113
-
'__root__' => 'Please check your data',
114
-
'age' => 'The {{name|raw}} field must be {{expected|quote}}'
115
-
]);
41
+
// Using list modifiers
42
+
v::templated(
43
+
'Status must be {{haystack|list:or}}',
44
+
v::in(['active', 'pending', 'archived']),
45
+
)->assert('deleted');
46
+
// → Status must be "active", "pending", or "archived"
116
47
```
117
-
118
-
## Custom Modifiers
119
-
120
-
At the moment, only the modifiers documented above are officially supported. Support for registering custom placeholder pipes is not part of the public API yet, but you can create your own modifiers.
0 commit comments