-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPAddress.php
More file actions
executable file
·52 lines (46 loc) · 1.2 KB
/
Copy pathIPAddress.php
File metadata and controls
executable file
·52 lines (46 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require_once('Noun.php');
// TODO: IPv6
class IPAddress implements NounLean // IPv4 address, and a NounLean oddity: the id is the info (TODO: IPv6 via a database? a clause noun??)
{
protected $ipv4;
public function __construct($info) // e.g. "123.45.67.89"
{
$this->ipv4 = $info;
}
static public function classname()
{
return NounClass::IPAddress;
}
public function info()
{
return $this->ipv4;
}
static public function selectId($id)
{
return new static(long2ip(intval($id)));
}
static public function selectInfo($ipv4)
{
return new static($ipv4);
}
// public function is()
// {
// return FALSE !== ip2long($this->ipv4);
// }
public function stow()
{
}
public function id()
{
// if ($this->is()) {
return sprintf("%u", ip2long($this->ipv4));
// } else {
// return FALSE;
// }
}
public function assertValid($classname = NULL)
{
NounLean_assertValid($this, $classname);
}
}