8000 minor #20138 [HttpFoundation] Add new parameters to `IpUtils::anonymi… · symfony/symfony-docs@55d50b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55d50b0

Browse files
committed
minor #20138 [HttpFoundation] Add new parameters to IpUtils::anonymize() (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- [HttpFoundation] Add new parameters to `IpUtils::anonymize()` Related to symfony/symfony#58038 Commits ------- 84da11c [HttpFoundation] Add new parameters to `IpUtils::anonymize()`
2 parents 0f3d37c + 84da11c commit 55d50b0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/http_foundation.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,23 @@ analysis purposes. Use the ``anonymize()`` method from the
362362
$anonymousIpv6 = IpUtils::anonymize($ipv6);
363363
// $anonymousIpv6 = '2a01:198:603:10::'
364364

365+
If you need even more anonymization, you can use the second and third parameters
366+
of the ``anonymize()`` method to specify the number of bytes that should be
367+
anonymized depending on the IP address format::
368+
369+
$ipv4 = '123.234.235.236';
370+
$anonymousIpv4 = IpUtils::anonymize($ipv4, v4Bytes: 3);
371+
// $anonymousIpv4 = '123.0.0.0'
372+
373+
$ipv6 = '2a01:198:603:10:396e:4789:8e99:890f';
374+
$anonymousIpv6 = IpUtils::anonymize($ipv6, v6Bytes: 10);
375+
// $anonymousIpv6 = '2a01:198:603::'
376+
377+
.. versionadded:: 7.2
378+
379+
The ``v4Bytes`` and ``v6Bytes`` parameters of the ``anonymize()`` method
380+
were introduced in Symfony 7.2.
381+
365382
Check If an IP Belongs to a CIDR Subnet
366383
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367384

0 commit comments

Comments
 (0)
0