Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"Warning":6,"Respect\\StringFormatter\\Test\\Unit\\TemplateFormatterTest::testShouldFormatString":4},"times":{"Warning":0.001,"Respect\\StringFormatter\\Test\\Unit\\TemplateFormatterTest::testShouldFormatString":0.001}}
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ echo f::create()
// Output: 1234 12** **** 1234
```

### Using Formatters as Modifiers

The `PlaceholderFormatter` allows you to use any formatter as a modifier within templates:

```php
use Respect\StringFormatter\PlaceholderFormatter;

$formatter = new PlaceholderFormatter([
'date' => '2024-01-15',
'amount' => '1234.56',
'phone' => '1234567890',
]);

echo $formatter->format('Date: {{date|date:Y/m/d}}, Amount: ${{amount|number:2}}, Phone: {{phone|pattern:(###) ###-####}}');
// Output: Date: 2024/01/15, Amount: $1,234.56, Phone: (123) 456-7890
```

See the [PlaceholderFormatter documentation](docs/PlaceholderFormatter.md) and [FormatterModifier documentation](docs/modifiers/FormatterModifier.md) for more details.

## Formatters

| Formatter | Description |
Expand Down
Loading
Loading