Skip to content

Commit 8f7f854

Browse files
Fix code style and update README with formatter modifier examples
Co-authored-by: henriquemoody <154023+henriquemoody@users.noreply.github.com>
1 parent b7b0136 commit 8f7f854

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ echo f::create()
3535
// Output: 1234 12** **** 1234
3636
```
3737

38+
### Using Formatters as Modifiers
39+
40+
The `PlaceholderFormatter` allows you to use any formatter as a modifier within templates:
41+
42+
```php
43+
use Respect\StringFormatter\PlaceholderFormatter;
44+
45+
$formatter = new PlaceholderFormatter([
46+
'date' => '2024-01-15',
47+
'amount' => '1234.56',
48+
'phone' => '1234567890',
49+
]);
50+
51+
echo $formatter->format('Date: {{date|date:Y/m/d}}, Amount: ${{amount|number:2}}, Phone: {{phone|pattern:(###) ###-####}}');
52+
// Output: Date: 2024/01/15, Amount: $1,234.56, Phone: (123) 456-7890
53+
```
54+
55+
See the [PlaceholderFormatter documentation](docs/PlaceholderFormatter.md) and [FormatterModifier documentation](docs/modifiers/FormatterModifier.md) for more details.
56+
3857
## Formatters
3958

4059
| Formatter | Description |

src/Modifiers/FormatterModifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
use Respect\StringFormatter\Modifier;
1717
use Throwable;
1818

19+
use function array_slice;
1920
use function explode;
2021
use function is_string;
2122
use function ucfirst;
22-
use function array_slice;
2323

2424
final readonly class FormatterModifier implements Modifier
2525
{
@@ -70,7 +70,7 @@ private function tryCreateFormatter(string $name, array $arguments): Formatter|n
7070

7171
try {
7272
$reflection = new ReflectionClass($class);
73-
73+
7474
return $reflection->newInstanceArgs($arguments);
7575
} catch (ReflectionException) {
7676
return null;

0 commit comments

Comments
 (0)