Skip to content

Commit 5b47f4f

Browse files
authored
Merge pull request #8282 from SadiHassan/mask-func-doc-v0
Doc for `Text::mask()`
2 parents 14db7d6 + 20b9119 commit 5b47f4f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

docs/en/appendices/5-4-migration-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ version is reported as `unknown`), the header is omitted.
134134
path manipulation. See [Filesystem Utilities](../core-libraries/filesystem.md).
135135
- `Security::encrypt()` can now be configured to use longer keys with separate encryption and authentication keys that are derived from the provided key.
136136
You can set `Security.encryptWithRawKey` to enable this behavior. See [here](https://github.com/cakephp/cakephp/pull/19325) for more details.
137+
- Added `Text::mask()` method which masks a portion of a string with a repeated character. See [Text Masking](../core-libraries/text.md#text-masking) for more details.
137138

138139
### Collection
139140

docs/en/core-libraries/text.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,32 @@ Output:
453453

454454
red, orange, yellow, green, blue, indigo and violet
455455

456+
## Text Masking
457+
458+
### Text::mask()
459+
460+
`method` Cake\\Utility\\Text::**mask**(string $string, int $offset, ?int $length = null, string $maskCharacter = '*'): string
461+
462+
Masks a portion of a string with a repeated character.
463+
464+
Replaces characters starting at `$offset` for `$length` characters with `$maskCharacter`.
465+
If `$length` is `null`, masking continues to the end of the string.
466+
Negative offsets are supported and are calculated from the end of the string.
467+
468+
```php
469+
$creditCardNumber = '4909090909091234';
470+
471+
// Called as TextHelper
472+
echo $this->Text->mask($creditCardNumber, 0, 12, '*');
473+
474+
// Called as Text
475+
use Cake\Utility\Text;
476+
477+
echo Text::mask($creditCardNumber, 0, 12, '*');
478+
```
479+
480+
Output:
481+
482+
************1234
483+
456484
<!-- end-text -->

0 commit comments

Comments
 (0)