Example #1
0
 /**
  * @inheritdoc
  */
 public function stringify(RangeInterface $range)
 {
     if ($range->getStart()->getIntValue() !== $range->getEnd()->getIntValue()) {
         throw new \InvalidArgumentException('SingleIP range accepts only ranges with equal start and end IPs');
     }
     return (string) $range->getStart();
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function stringify(RangeInterface $range)
 {
     if ($range->getStart()->getIntValue() == $range->getEnd()->getIntValue()) {
         return (string) $range->getStart();
     }
     $start = explode('.', (string) $range->getStart());
     $end = explode('.', (string) $range->getEnd());
     $wildcard = array();
     for ($i = 0; $i < 4; $i++) {
         $byteS = $start[$i];
         $byteE = $end[$i];
         if ($byteS == '0' && $byteE == '255') {
             $wildcard[$i] = '*';
         } elseif ($byteS == $byteE) {
             $wildcard[$i] = $byteS;
         } else {
             throw new \InvalidArgumentException("Range [{$range->getStart()}-{$range->getEnd()} can not be converted to wildcard");
         }
     }
     return implode('.', $wildcard);
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function stringify(RangeInterface $range)
 {
     $start = $range->getStart()->getIntValue();
     $end = $range->getEnd()->getIntValue();
     $listCIDRs = array();
     while ($end >= $start) {
         $maxsize = self::countSetBits(-($start & -$start));
         $maxdiff = 32 - intval(log($end - $start + 1) / log(2));
         $size = $maxsize > $maxdiff ? $maxsize : $maxdiff;
         $listCIDRs[] = long2ip($start) . "/{$size}";
         $start += pow(2, 32 - $size);
     }
     return implode(',', $listCIDRs);
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function stringify(RangeInterface $range)
 {
     return $range->getStart() . '-' . $range->getEnd();
 }
Example #5
0
 /**
  * Rewind the Iterator to the first element
  */
 public function rewind()
 {
     $this->current = $this->range->getStart();
 }