Skip to content

Commit d9664ba

Browse files
[HttpFoundation] Add new parameters to IpUtils::anonymize()
1 parent f1c7127 commit d9664ba

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/http_foundation.rst

+17
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, anonymizedBytesForV4: 3);
371+
// $anonymousIpv4 = '123.0.0.0'
372+
373+
$ipv6 = '2a01:198:603:10:396e:4789:8e99:890f';
374+
$anonymousIpv6 = IpUtils::anonymize($ipv6, anonymizedBytesForV6: 10);
375+
// $anonymousIpv6 = '2a01:198:603::'
376+
377+
.. versionadded:: 7.2
378+
379+
The ``anonymizedBytesForV4`` and ``anonymizedBytesForV6`` arguments of
380+
the ``anonymize()`` method were introduced in Symfony 7.2.
381+
365382
Check If an IP Belongs to a CIDR Subnet
366383
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367384

0 commit comments

Comments
 (0)