Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 class IpAddress implements Stringable
00016 {
00017 private $longIp = null;
00018
00022 public static function create($ip)
00023 {
00024 return new self($ip);
00025 }
00026
00027 public function __construct($ip)
00028 {
00029 $this->setIp($ip);
00030 }
00031
00035 public function setIp($ip)
00036 {
00037 $long = ip2long($ip);
00038
00039 if ($long === false)
00040 throw new WrongArgumentException('wrong ip given');
00041
00042 $this->longIp = $long;
00043
00044 return $this;
00045 }
00046
00047 public function getLongIp()
00048 {
00049 return $this->longIp;
00050 }
00051
00052 public function toString()
00053 {
00054 return long2ip($this->longIp);
00055 }
00056
00057 public function toSignedInt()
00058 {
00059 return TypesUtils::unsignedToSigned($this->longIp);
00060 }
00061 }
00062 ?>