1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-12 18:02:39 +01:00
phorge-arcanist/src/ip/PhutilIPAddress.php
epriestley 9b74cb4ee6 Fully merge "libphutil/" into "arcanist/"
Summary: Ref T13395. Moves all remaining code in "libphutil/" into "arcanist/".

Test Plan: Ran various arc workflows, although this probably has some remaining rough edges.

Maniphest Tasks: T13395

Differential Revision: https://secure.phabricator.com/D20980
2020-02-12 15:17:38 -08:00

43 lines
975 B
PHP

<?php
/**
* Represent and manipulate IPv4 and IPv6 addresses.
*/
abstract class PhutilIPAddress
extends Phobject {
private function __construct() {
// <private>
}
abstract public function toBits();
abstract public function getBitCount();
abstract public function getAddress();
public static function newAddress($in) {
if ($in instanceof PhutilIPAddress) {
return clone $in;
}
try {
return PhutilIPv4Address::newFromString($in);
} catch (Exception $ex) {
// Continue, trying the address as IPv6 instead.
}
try {
return PhutilIPv6Address::newFromString($in);
} catch (Exception $ex) {
// Continue, throwing a more tailored exception below.
}
throw new Exception(
pht(
'IP address "%s" is not properly formatted. Expected an IPv4 address '.
'like "%s", or an IPv6 address like "%s".',
$in,
'23.45.67.89',
'2345:6789:0123:abcd::'));
}
}