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 /* $Id: IpRange.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     class IpRange implements SingleRange
00017     {
00018         private $startIp    = null;
00019         private $endIp      = null;
00020         
00024         public static function create(IpAddress $startIp, IpAddress $endIp)
00025         {
00026             return new self($startIp, $endIp);
00027         }
00028         
00029         public function __construct(IpAddress $startIp, IpAddress $endIp)
00030         {
00031             if ($startIp->getLongIp() > $endIp->getLongIp())
00032                 throw new WrongArgumentException(
00033                     'start ip must be lower than ip end'
00034                 );
00035             
00036             $this->startIp  = $startIp;
00037             $this->endIp    = $endIp;
00038         }
00039         
00043         public function getStart()
00044         {
00045             return $this->startIp;
00046         }
00047         
00051         public function setStart(IpAddress $startIp)
00052         {
00053             $this->startIp = $startIp;
00054             
00055             return $this;
00056         }
00057         
00061         public function getEnd()
00062         {
00063             return $this->endIp;
00064         }
00065         
00069         public function setEnd(IpAddress $endIp)
00070         {
00071             $this->endIp = $endIp;
00072             
00073             return $this->endIp;
00074         }
00075         
00076         public function contains(/*IpAddress*/ $probe)
00077         {
00078             return (
00079                 ($this->startIp->getLongIp() <= $probe->getLongIp())
00080                 && ($this->endIp->getLongIp() >= $probe->getLongIp())
00081             );
00082         }
00083     }
00084 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4