Skip to content

Commit aee9123

Browse files
committed
Simplify placeholder pipes documentation
Reference StringFormatter project for modifier details instead of duplicating documentation. Assisted-by: Claude Code (Opus 4.5)
1 parent 316200d commit aee9123

1 file changed

Lines changed: 10 additions & 83 deletions

File tree

docs/messages/placeholder-pipes.md

Lines changed: 10 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,12 @@ SPDX-License-Identifier: MIT
55

66
# Placeholder Pipes
77

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.
99

1010
## Usage
1111

1212
To use a placeholder pipe, modify your placeholder like this: `{{placeholder|modifier}}`
1313

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-
2914
```php
3015
v::templated(
3116
'The {{field|raw}} field is required',
@@ -36,60 +21,11 @@ v::templated(
3621
// (instead of: The "email" field is required)
3722
```
3823

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',
84-
v::callback(fn(User $user) => $user->hasRoles(['admin', 'editor'])),
85-
['roles' => ['admin', 'editor']],
86-
)->assert($user);
87-
// → User must have "admin" and "editor" roles to perform this action
88-
```
24+
## Available Modifiers
8925

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).
9127

92-
Placeholder pipes work with both inline templates and `Templated` validators:
28+
## Examples
9329

9430
```php
9531
// Using with assert()
@@ -101,20 +37,11 @@ v::templated(
10137
v::email(),
10238
['field' => 'email']
10339
)->assert($input);
104-
```
105-
106-
## Nested Validators
10740

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"
11647
```
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

Comments
 (0)