/**
  * @return IpAddress
  **/
 public function getEnd()
 {
     if (!$this->end) {
         $this->end = IpAddress::create(long2ip($this->ip->getLongIp() | ~$this->longMask));
     }
     return $this->end;
 }
 public function testWithObjects()
 {
     $criteria = Criteria::create(TestUser::dao())->add(Expression::containsIp(IpRange::create('192.168.1.1-192.168.1.255'), 'ip'))->addProjection(Projection::property('id'));
     $this->assertEquals($criteria->toDialectString(PostgresDialect::me()), 'SELECT "test_user"."id" FROM "test_user" WHERE "test_user"."ip" <<= \'192.168.1.1-192.168.1.255\'');
     $criteria = Criteria::create(TestInternetProvider::dao())->add(Expression::containsIp('range', IpAddress::create('42.42.42.42')))->addProjection(Projection::property('id'));
     $this->assertEquals($criteria->toDialectString(PostgresDialect::me()), 'SELECT "test_internet_provider"."id" FROM "test_internet_provider" WHERE \'42.42.42.42\' <<= "test_internet_provider"."range"');
 }
 public function testIpRangeProperty()
 {
     foreach (DBTestPool::me()->getPool() as $db) {
         DBPool::me()->setDefault($db);
         $akado = TestInternetProvider::create()->setName('Akada')->setRange(IpRange::create(IpAddress::create('192.168.1.1'), IpAddress::create('192.168.1.42')));
         TestInternetProvider::dao()->add($akado);
         $plainRange = Criteria::create(TestInternetProvider::dao())->addProjection(Projection::property('range'))->add(Expression::eq('name', 'Akada'))->getCustom();
         $this->assertEquals($plainRange['range'], '192.168.1.1-192.168.1.42');
         TestInternetProvider::dao()->add(TestInternetProvider::create()->setName('DomRu')->setRange(IpRange::create('192.168.2.0/24')));
         $list = Criteria::create(TestInternetProvider::dao())->addOrder('id')->getList();
         $this->assertEquals(count($list), 2);
     }
 }
 public function testContains()
 {
     $IpNetwork = IpNetwork::create(IpAddress::create('83.149.5.0'), 24);
     $this->assertTrue($IpNetwork->contains(IpAddress::create('83.149.5.0')));
     $this->assertTrue($IpNetwork->contains(IpAddress::create('83.149.5.1')));
     $this->assertTrue($IpNetwork->contains(IpAddress::create('83.149.5.4')));
     $this->assertTrue($IpNetwork->contains(IpAddress::create('83.149.5.255')));
     $this->assertFalse($IpNetwork->contains(IpAddress::create('83.149.4.255')));
     $this->assertFalse($IpNetwork->contains(IpAddress::create('83.149.6.1')));
     $IpNetwork = IpNetwork::create(IpAddress::create('83.149.24.64'), 26);
     $this->assertTrue($IpNetwork->contains(IpAddress::create('83.149.24.64')));
     $this->assertTrue($IpNetwork->contains(IpAddress::create('83.149.24.66')));
     $this->assertTrue($IpNetwork->contains(IpAddress::create('83.149.24.127')));
     $this->assertFalse($IpNetwork->contains(IpAddress::create('83.149.24.63')));
     $this->assertFalse($IpNetwork->contains(IpAddress::create('83.149.25.64')));
 }
 public function testBase()
 {
     $prm = Primitive::ipAddress('ip');
     $this->assertTrue($prm->importValue('127.0.0.1'));
     $this->assertTrue($prm->importValue('254.254.254.254'));
     $this->assertTrue($prm->importValue('0.0.0.0'));
     $this->assertFalse($prm->importValue('10.0.0'));
     $this->assertFalse($prm->importValue('42.42.42.360'));
     $this->assertFalse($prm->importValue('10.0.256'));
     $prmWithDefault = Primitive::ipAddress('ip')->setDefault(IpAddress::create('42.42.42.42'));
     $this->assertEquals($prmWithDefault->getActualValue()->toString(), '42.42.42.42');
     $prmWithDefault->import(array('ip' => '43.43.43.43'));
     $this->assertEquals($prmWithDefault->getActualValue()->toString(), '43.43.43.43');
     $prmWithDefault->importValue(IpAddress::create('8.8.8.8'));
     //google public dns ;)
     $this->assertEquals($prmWithDefault->getActualValue()->toString(), '8.8.8.8');
 }
 public function testCreation()
 {
     $range = IpRange::create('192.168.2.1-192.168.255.255');
     $anotherRange = IpRange::create(IpAddress::create('192.168.2.1'), IpAddress::create('192.168.255.255'));
     $this->assertEquals($range->toString(), $anotherRange->toString());
     try {
         $range = IpRange::create('192.168.2.1-192.168.255.666');
         $this->fail();
     } catch (WrongArgumentException $e) {
         /**/
     }
     try {
         $range = IpRange::create('192.168.666.1-192.168.255.254');
         $this->fail();
     } catch (WrongArgumentException $e) {
         /**/
     }
     try {
         $range = IpRange::create(array(array(array(false))));
         $this->fail();
     } catch (WrongArgumentException $e) {
         /**/
     }
     $slashRange = IpRange::create('192.168.1.0/30');
     $this->assertEquals('192.168.1.0', $slashRange->getStart()->toString());
     $this->assertEquals('192.168.1.3', $slashRange->getEnd()->toString());
     try {
         $range = IpRange::create('192.168.1.0/4');
         $this->fail();
     } catch (WrongArgumentException $e) {
         /**/
     }
     $range = IpRange::create('8.8/16');
     $this->assertEquals($range->toString(), '8.8.0.0-8.8.255.255');
     $range = IpRange::create('192.168.1.1');
     $this->assertEquals($range->getStart()->toString(), $range->getEnd()->toString());
 }
 /**
  * @return TestUser
  */
 private function spawnUser($options = array())
 {
     $options += array('id' => '77', 'credentials' => Credentials::create(), 'lastLogin' => Timestamp::create('2011-12-31'), 'registered' => Timestamp::create('2011-12-30'), 'strangeTime' => Time::create('01:23:45'), 'city' => null, 'firstOptional' => null, 'secondOptional' => null, 'url' => HttpUrl::create()->parse('https://www.github.com'), 'properties' => Hstore::make(array('a' => 'apple', 'b' => 'bananas')), 'ip' => IpAddress::create('127.0.0.1'));
     return $this->spawnObject(TestUser::create(), $options);
 }
 public function testSignedLongToIpToSignedLong()
 {
     foreach ($this->ips as $ip) {
         $this->assertEquals(IpAddress::create(long2ip($ip[1]))->toSignedInt(), $ip[1]);
     }
 }
Exemplo n.º 9
0
 private function createFromString($string)
 {
     if (preg_match(self::SINGLE_IP_PATTERN, $string)) {
         $ip = IpAddress::create($string);
         $this->setup($ip, $ip);
     } elseif (preg_match(self::IP_SLASH_PATTERN, $string)) {
         list($ip, $mask) = explode('/', $string);
         $this->createFromSlash($ip, $mask);
     } elseif (preg_match(self::INTERVAL_PATTERN, $string)) {
         $this->createFromInterval($string);
     } else {
         throw new WrongArgumentException('strange parameters received');
     }
 }