From a8649f0246d95148a7d2287f277072a779cc65e8 Mon Sep 17 00:00:00 2001 From: Mallik Hassan Date: Mon, 27 Apr 2026 11:03:42 -0300 Subject: [PATCH 1/3] Doc for maskValue() function --- docs/en/appendices/5-4-migration-guide.md | 1 + docs/en/core-libraries/text.md | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/en/appendices/5-4-migration-guide.md b/docs/en/appendices/5-4-migration-guide.md index 3ab9a579c8..a7440c2660 100644 --- a/docs/en/appendices/5-4-migration-guide.md +++ b/docs/en/appendices/5-4-migration-guide.md @@ -156,6 +156,7 @@ version is reported as `unknown`), the header is omitted. - `Security::encrypt()` can now be configured to use longer keys with separate encryption and authentication keys that are derived from the provided key. You can set `Security.encryptWithRawKey` to enable this behavior. See [here](https://github.com/cakephp/cakephp/pull/19325) for more details. - 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. +- Added `Text::maskValue()` method which masks all occurrences of given substrings within a string using a repeated character. See [Text Masking](../core-libraries/text.md#text-masking) for more details. ### View diff --git a/docs/en/core-libraries/text.md b/docs/en/core-libraries/text.md index 1a3a73f55a..4ad6793a6d 100644 --- a/docs/en/core-libraries/text.md +++ b/docs/en/core-libraries/text.md @@ -465,20 +465,26 @@ Replaces characters starting at `$offset` for `$length` characters with `$maskCh If `$length` is `null`, masking continues to the end of the string. Negative offsets are supported and are calculated from the end of the string. +### Text::maskValue() + +`method` Cake\\Utility\\Text::**maskValue**(string $string, array $needles, string $maskCharacter = '*'): string + +Masks all occurrences of given substring(s) within a string using a repeated character. +Each occurrence of the provided substring(s) will be replaced by a sequence of the masking character. + ```php -$creditCardNumber = '4909090909091234'; // Called as TextHelper -echo $this->Text->mask($creditCardNumber, 0, 12, '*'); +echo $this->Text->maskValue('4111111111111234', ['411', '112'], '*'); // Called as Text use Cake\Utility\Text; -echo Text::mask($creditCardNumber, 0, 12, '*'); +echo Text::maskValue('4111111111111234', ['411', '112'], '*'); ``` Output: - ************1234 + ***11111111***34 From 69990589885eeaa6771876ea470069bd2cec85cd Mon Sep 17 00:00:00 2001 From: Mallik Hassan Date: Mon, 27 Apr 2026 11:07:08 -0300 Subject: [PATCH 2/3] Doc for maskValue() function --- docs/en/core-libraries/text.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/en/core-libraries/text.md b/docs/en/core-libraries/text.md index 4ad6793a6d..83939aa3c1 100644 --- a/docs/en/core-libraries/text.md +++ b/docs/en/core-libraries/text.md @@ -465,6 +465,22 @@ Replaces characters starting at `$offset` for `$length` characters with `$maskCh If `$length` is `null`, masking continues to the end of the string. Negative offsets are supported and are calculated from the end of the string. +```php +$creditCardNumber = '4909090909091234'; + +// Called as TextHelper +echo $this->Text->mask($creditCardNumber, 0, 12, '*'); + +// Called as Text +use Cake\Utility\Text; + +echo Text::mask($creditCardNumber, 0, 12, '*'); +``` + +Output: + + ************1234 + ### Text::maskValue() `method` Cake\\Utility\\Text::**maskValue**(string $string, array $needles, string $maskCharacter = '*'): string @@ -486,5 +502,4 @@ echo Text::maskValue('4111111111111234', ['411', '112'], '*'); Output: ***11111111***34 - From 8f4f6735f05c36669a766ce405c50e4e08a30804 Mon Sep 17 00:00:00 2001 From: Mallik Hassan Date: Mon, 27 Apr 2026 20:28:11 -0300 Subject: [PATCH 3/3] Update text.md Co-authored-by: Mark Story --- docs/en/core-libraries/text.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/en/core-libraries/text.md b/docs/en/core-libraries/text.md index 83939aa3c1..ff8703372e 100644 --- a/docs/en/core-libraries/text.md +++ b/docs/en/core-libraries/text.md @@ -489,7 +489,6 @@ Masks all occurrences of given substring(s) within a string using a repeated cha Each occurrence of the provided substring(s) will be replaced by a sequence of the masking character. ```php - // Called as TextHelper echo $this->Text->maskValue('4111111111111234', ['411', '112'], '*');