Changeset 52244 for trunk/src/wp-includes/Requests/Ipv6.php
- Timestamp:
- 11/25/2021 01:10:30 AM (5 years ago)
- File:
-
- 1 moved
-
trunk/src/wp-includes/Requests/Ipv6.php (moved) (moved from trunk/src/wp-includes/Requests/IPv6.php ) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/Requests/Ipv6.php
r52243 r52244 3 3 * Class to validate and to work with IPv6 addresses 4 4 * 5 * @package Requests 6 * @subpackage Utilities 5 * @package Requests\Utilities 7 6 */ 7 8 namespace WpOrg\Requests; 9 10 use WpOrg\Requests\Exception\InvalidArgument; 11 use WpOrg\Requests\Utility\InputValidator; 8 12 9 13 /** … … 13 17 * entirely rewritten. 14 18 * 15 * @package Requests 16 * @subpackage Utilities 19 * @package Requests\Utilities 17 20 */ 18 class Requests_IPv6 {21 final class Ipv6 { 19 22 /** 20 23 * Uncompresses an IPv6 address … … 31 34 * @author Josh Peck <jmp at joshpeck dot org> 32 35 * @copyright 2003-2005 The PHP Group 33 * @license http://www.opensource.org/licenses/bsd-license.php 34 * @param string $ip An IPv6 address 36 * @license https://opensource.org/licenses/bsd-license.php 37 * 38 * @param string|Stringable $ip An IPv6 address 35 39 * @return string The uncompressed IPv6 address 40 * 41 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed argument is not a string or a stringable object. 36 42 */ 37 43 public static function uncompress($ip) { 44 if (InputValidator::is_string_or_stringable($ip) === false) { 45 throw InvalidArgument::create(1, '$ip', 'string|Stringable', gettype($ip)); 46 } 47 48 $ip = (string) $ip; 49 38 50 if (substr_count($ip, '::') !== 1) { 39 51 return $ip; … … 79 91 * 0:0:0:0:0:0:0:1 -> ::1 80 92 * 81 * @see uncompress() 93 * @see \WpOrg\Requests\IPv6::uncompress() 94 * 82 95 * @param string $ip An IPv6 address 83 96 * @return string The compressed IPv6 address 84 97 */ 85 98 public static function compress($ip) { 86 // Prepare the IP to be compressed 99 // Prepare the IP to be compressed. 100 // Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method. 87 101 $ip = self::uncompress($ip); 88 102 $ip_parts = self::split_v6_v4($ip); … … 125 139 * @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part 126 140 */ 127 pr otectedstatic function split_v6_v4($ip) {141 private static function split_v6_v4($ip) { 128 142 if (strpos($ip, '.') !== false) { 129 143 $pos = strrpos($ip, ':'); 130 144 $ipv6_part = substr($ip, 0, $pos); 131 145 $ipv4_part = substr($ip, $pos + 1); 132 return array($ipv6_part, $ipv4_part);133 } 134 else { 135 return array($ip, '');146 return [$ipv6_part, $ipv4_part]; 147 } 148 else { 149 return [$ip, '']; 136 150 } 137 151 } … … 146 160 */ 147 161 public static function check_ipv6($ip) { 162 // Note: Input validation is handled in the `uncompress()` method, which is the first call made in this method. 148 163 $ip = self::uncompress($ip); 149 164 list($ipv6, $ipv4) = self::split_v6_v4($ip);
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)