Skip to content

Commit a47564c

Browse files
Add documentation for multiple pipes feature
- Documented multiple pipes syntax and usage in PlaceholderFormatter.md - Added examples showing chained modifiers - Explained escaped pipes (\|) behavior - Updated template syntax rules Co-authored-by: henriquemoody <[email protected]>
1 parent fb5df93 commit a47564c

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

docs/PlaceholderFormatter.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ echo $formatter->format('Phone: {{phone|pattern:(###) ###-####}}');
5959

6060
See the [FormatterModifier](modifiers/FormatterModifier.md) documentation for all available formatters and options.
6161

62+
#### Multiple Pipes
63+
64+
You can chain multiple modifiers together using the pipe (`|`) character. Modifiers are applied sequentially from left to right.
65+
66+
```php
67+
$formatter = new PlaceholderFormatter([
68+
'phone' => '1234567890',
69+
'value' => '12345',
70+
]);
71+
72+
// Apply pattern formatting, then mask sensitive data
73+
echo $formatter->format('Phone: {{phone|pattern:(###) ###-####|mask:6-12}}');
74+
// Output: Phone: (123) ******90
75+
76+
// Apply number formatting, then mask
77+
echo $formatter->format('Value: {{value|number:0|mask:1-3}}');
78+
// Output: Value: ***45
79+
```
80+
81+
**Escaped Pipes:** If you need to use the pipe character (`|`) as part of a modifier argument (not as a separator), escape it with a backslash (`\|`):
82+
83+
```php
84+
$formatter = new PlaceholderFormatter(['value' => '123456']);
85+
86+
// Escaped pipe in pattern, then apply mask
87+
echo $formatter->format('{{value|pattern:###\|###|mask:1-3}}');
88+
// Output: ***|456
89+
```
90+
6291
You can also use other modifiers like `list` and `trans`:
6392

6493
```php
@@ -91,15 +120,17 @@ Formats with additional parameters merged with constructor parameters. Construct
91120

92121
## Template Syntax
93122

94-
Placeholders follow the format `{{name}}` where `name` is a valid parameter key. Modifiers can be added after a pipe: `{{name|modifier}}`.
123+
Placeholders follow the format `{{name}}` where `name` is a valid parameter key. Modifiers can be added after a pipe: `{{name|modifier}}`. Multiple modifiers can be chained: `{{name|modifier1|modifier2}}`.
95124

96125
**Rules:**
97126

98127
- Names must match `\w+` (letters, digits, underscore)
99128
- Names are case-sensitive
100129
- No whitespace inside braces or around the pipe
130+
- Multiple pipes are separated by `|` and applied sequentially
131+
- Escaped pipes (`\|`) within modifiers are treated as literal characters, not separators
101132

102-
**Valid:** `{{name}}`, `{{user_id}}`, `{{name|raw}}`
133+
**Valid:** `{{name}}`, `{{user_id}}`, `{{name|raw}}`, `{{value|date:Y-m-d|mask:1-5}}`
103134

104135
**Invalid:** `{name}`, `{{ name }}`, `{{first-name}}`, `{{}}`
105136

0 commit comments

Comments
 (0)