IpRange.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Vladimir A. Altuchov                            *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     class IpRange implements SingleRange
00016     {
00017         private $startIp    = null;
00018         private $endIp      = null;
00019         
00023         public static function create(IpAddress $startIp, IpAddress $endIp)
00024         {
00025             return new self($startIp, $endIp);
00026         }
00027         
00028         public function __construct(IpAddress $startIp, IpAddress $endIp)
00029         {
00030             if ($startIp->getLongIp() > $endIp->getLongIp())
00031                 throw new WrongArgumentException(
00032                     'start ip must be lower than ip end'
00033                 );
00034             
00035             $this->startIp  = $startIp;
00036             $this->endIp    = $endIp;
00037         }
00038         
00042         public function getStart()
00043         {
00044             return $this->startIp;
00045         }
00046         
00050         public function setStart(IpAddress $startIp)
00051         {
00052             $this->startIp = $startIp;
00053             
00054             return $this;
00055         }
00056         
00060         public function getEnd()
00061         {
00062             return $this->endIp;
00063         }
00064         
00068         public function setEnd(IpAddress $endIp)
00069         {
00070             $this->endIp = $endIp;
00071             
00072             return $this;
00073         }
00074         
00075         public function contains(/* IpAddress */ $probe)
00076         {
00077             Assert::isInstance($probe, 'IpAddress');
00078             
00079             return (
00080                 ($this->startIp->getLongIp() <= $probe->getLongIp())
00081                 && ($this->endIp->getLongIp() >= $probe->getLongIp())
00082             );
00083         }
00084     }
00085 ?>