Skip to content

Commit 3696f0f

Browse files
committed
Add global 'f' alias for FormatterBuilder
Register a class alias that maps 'f' to FormatterBuilder, auto-loaded via Composer's files directive. This provides a concise entry point for building formatter chains (e.g., f::create()->mask(...)) without requiring an explicit use statement, simplifying usage in consumer code and aligning the README examples with the new convention. Assisted-by: Claude Code (Claude Opus 4.6)
1 parent 2319f4c commit 3696f0f

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* export-ignore
2+
/aliases.php -export-ignore
23
/composer.json -export-ignore
34
/src -export-ignore
45
/LICENSE -export-ignore

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ composer require respect/string-formatter
2626
You can use individual formatters directly or chain multiple formatters together using the `FormatterBuilder`:
2727

2828
```php
29-
use Respect\StringFormatter\FormatterBuilder as f;
30-
3129
echo f::create()
3230
->mask('7-12')
3331
->pattern('#### #### #### ####')

aliases.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* SPDX-License-Identifier: MIT
5+
* SPDX-FileCopyrightText: (c) Respect Project Contributors
6+
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
7+
* SPDX-FileContributor: Andy Wendt <andy@awendt.com>
8+
* SPDX-FileContributor: Graham Campbell <graham@mineuk.com>
9+
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
10+
* SPDX-FileContributor: Nick Lombard <github@jigsoft.co.za>
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
use Respect\StringFormatter\FormatterBuilder;
16+
17+
if (!class_exists('f')) {
18+
class_alias(FormatterBuilder::class, 'f');
19+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"autoload": {
2525
"psr-4": {
2626
"Respect\\StringFormatter\\": "src/"
27-
}
27+
},
28+
"files": ["aliases.php"]
2829
},
2930
"autoload-dev": {
3031
"psr-4": {

0 commit comments

Comments
 (0)