Commit 676d264
committed
Add modifier support to PlaceholderFormatter
Although basic interpolation is useful, we often want to handle parameters
differently, not using the standard modification we apply to them. This commit
introduces modifiers, a concept already present in Respect\Validation.
We use a familiar `{{value|modifier}}` syntax found in many popular template
engines. To handle different types of modifiers, I implemented a Chain of
Responsibility, where each modifier delegates to the next one when it cannot
handle them.
The `StringifyModifier` remains the default fallback, ensuring that we don't
lose the robust type-handling we previously built, but I've also made some
changes to it. I realise that for Respect\Validation, we have a strong need to
add "quotes" around strings because they represent values that were just
validated, but in the context of placeholder replacement, this behaviour is
undesirable.
I've created the `AutoQuoteModifier`, which quotes scalar values by default and
provides a `|raw` pipe to bypass quoting when clean output is needed. This
allows Validation to retain its quoting behaviour while keeping the default
`PlaceholderFormatter` chain simple.
Assisted-by: OpenCode (GLM-4.6)
Assisted-by: Gemini 3 (Thinking)1 parent fb2db2d commit 676d264
17 files changed
Lines changed: 688 additions & 351 deletions
File tree
- docs
- contributing
- modifiers
- src
- Modifiers
- tests
- Helper
- Unit
- Modifiers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
36 | 57 | | |
37 | 58 | | |
38 | 59 | | |
| |||
0 commit comments