Skip to content

Commit 3086b18

Browse files
committed
Merge branch '5.x' into 5.next
2 parents b9b8e1e + eb8a0ff commit 3086b18

3 files changed

Lines changed: 112 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ events are now registered while each plugin is bootstrapped.
241241
You can set `Security.encryptWithRawKey` to enable this behavior. See [here](https://github.com/cakephp/cakephp/pull/19325) for more details.
242242
- 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.
243243
- 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.
244+
- Added `Text::maskRegex()` and `Text::maskPartialRegex()` methods for masking
245+
regular expression matches. See [Text Masking](../core-libraries/text.md#text-masking)
246+
for more details.
244247

245248
### View
246249

docs/en/core-libraries/text.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,58 @@ echo Text::maskValue('4111111111111234', ['411', '112'], '*');
501501
Output:
502502

503503
***11111111***34
504+
505+
### Text::maskRegex()
506+
507+
`method` Cake\\Utility\\Text::**maskRegex**(string $string, array|string $patterns, string $maskCharacter = '*'): string
508+
509+
Masks all occurrences of given regular expression pattern(s) within a string
510+
using a repeated character. Each match is replaced by a sequence of the masking
511+
character with the same length as the match.
512+
513+
The `$patterns` argument accepts a single regular expression or an array of
514+
regular expressions. Empty patterns are ignored. `$maskCharacter` must be a
515+
single character.
516+
517+
```php
518+
// Called as TextHelper
519+
echo $this->Text->maskRegex('my pin is 1234', '/\d+/', '*');
520+
521+
// Called as Text
522+
use Cake\Utility\Text;
523+
524+
echo Text::maskRegex('token: abc123', '/[a-z0-9]+/', 'x');
525+
```
526+
527+
Output:
528+
529+
my pin is ****
530+
xxxxx: xxxxxx
531+
532+
### Text::maskPartialRegex()
533+
534+
`method` Cake\\Utility\\Text::**maskPartialRegex**(string $string, array|string $patterns, int $showLeading = 0, int $showTrailing = 0, string $maskCharacter = '*'): string
535+
536+
Masks all occurrences of given regular expression pattern(s) within a string,
537+
while preserving a number of leading and trailing characters from each match.
538+
539+
The `$showLeading` and `$showTrailing` arguments control how many characters at
540+
the start and end of each match are left unmasked. If their combined value is
541+
greater than or equal to the match length, the match is left unchanged. These
542+
values must be non-negative, and `$maskCharacter` must be a single character.
543+
544+
```php
545+
// Called as TextHelper
546+
echo $this->Text->maskPartialRegex('card: 4242424242424242', '/\d{16}/', 0, 4);
547+
548+
// Called as Text
549+
use Cake\Utility\Text;
550+
551+
echo Text::maskPartialRegex('Secret Codeword', '/\b\w+\b/', 1, 1);
552+
```
553+
554+
Output:
555+
556+
card: ************4242
557+
S****t C******d
504558
<!-- end-text -->

docs/en/development/dependency-injection.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,12 +1327,13 @@ class ArticlesController extends AppController
13271327
> - **Clarity**: Controller focuses on HTTP concerns, service handles business logic
13281328
> - **Maintainability**: Complex workflows are organized into focused classes
13291329
1330-
## Auto Wiring
1330+
## Auto-wiring with league/container
13311331

13321332
> [!WARNING]
13331333
> Auto-wiring is convenient but can impact performance. Enable caching in production environments.
13341334
1335-
Auto Wiring is turned off by default. To enable it:
1335+
When using the default `league/container` implementation, auto-wiring is turned
1336+
off by default. To enable it:
13361337

13371338
```php
13381339
// In src/Application.php
@@ -1360,3 +1361,55 @@ $container->delegate(
13601361
```
13611362

13621363
Read more about auto wiring in the [PHP League Container documentation](https://container.thephpleague.com/4.x/auto-wiring/).
1364+
1365+
## Built-in Container
1366+
1367+
::: info Added in version 5.4.0
1368+
:::
1369+
1370+
CakePHP includes its own PSR-11-compatible dependency injection container in
1371+
the `Cake\Container` namespace. The `league/container` implementation remains
1372+
the default so that existing applications continue to work unchanged. To use
1373+
the built-in container, set `App.container` to `cake` in `config/app.php`:
1374+
1375+
```php
1376+
return [
1377+
'App' => [
1378+
'container' => 'cake',
1379+
],
1380+
];
1381+
```
1382+
1383+
CakePHP exposes the built-in container through a compatibility bridge. Continue
1384+
to type-hint `Cake\Core\ContainerInterface` in your application's `services()`
1385+
method; service definitions using `add()`, `addShared()`, `extend()`, tags, and
1386+
delegates work with either implementation.
1387+
1388+
### Auto-wiring
1389+
1390+
Unlike the default `league/container` implementation, the built-in container
1391+
enables auto-wiring and caches auto-wired resolutions by default. It can create
1392+
concrete classes and resolve their class-typed constructor dependencies without
1393+
an explicit service definition:
1394+
1395+
```php
1396+
class OrderService
1397+
{
1398+
public function __construct(private PaymentGateway $gateway)
1399+
{
1400+
}
1401+
}
1402+
1403+
// Only the interface needs an explicit mapping. OrderService is auto-wired.
1404+
$container->add(PaymentGateway::class, StripePaymentGateway::class);
1405+
```
1406+
1407+
Define services explicitly when a constructor needs an interface, a scalar or
1408+
array value, or another value that cannot be determined from its type. Explicit
1409+
definitions also let you configure constructor arguments and control whether a
1410+
service is shared.
1411+
1412+
When using the built-in container, do not add
1413+
`League\Container\ReflectionContainer`; auto-wiring is already enabled. The
1414+
following [auto-wiring instructions](#auto-wiring-with-leaguecontainer) apply
1415+
only when using the default `league/container` implementation.

0 commit comments

Comments
 (0)