00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 class IpAddress implements Stringable
00017 {
00018 private $longIp = null;
00019
00023 public static function create($ip)
00024 {
00025 return new self($ip);
00026 }
00027
00028 public function __construct($ip)
00029 {
00030 $this->setIp($ip);
00031 }
00032
00036 public function setIp($ip)
00037 {
00038 if (ip2long($ip) === -1)
00039 throw new WrongArgumentException('wrong ip given');
00040
00041 $this->longIp = ip2long($ip);
00042
00043 return $this;
00044 }
00045
00046 public function getLongIp()
00047 {
00048 return $this->longIp;
00049 }
00050
00051 public function toString()
00052 {
00053 return long2ip($this->longIp);
00054 }
00055 }
00056 ?>