1: <?php
2:
3: namespace Saklient\Cloud\Resources;
4:
5: require_once __DIR__ . "/../../../Saklient/Util.php";
6: use \Saklient\Util;
7: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
8: use \Saklient\Errors\SaklientException;
9:
10: /**
11: * IPv4ネットワークのIPアドレス範囲。
12: *
13: * @property-read string $first 開始アドレス
14: * @property-read string $last 終了アドレス
15: * @property-read \ArrayObject $asArray * この範囲に属するIPv4アドレスの一覧を取得します。
16: */
17: class Ipv4Range {
18:
19: /**
20: * @private
21: * @access protected
22: * @ignore
23: * @var string
24: */
25: protected $_first;
26:
27: /**
28: * @access public
29: * @ignore
30: * @return string
31: */
32: public function get_first()
33: {
34: return $this->_first;
35: }
36:
37:
38:
39: /**
40: * @private
41: * @access protected
42: * @ignore
43: * @var string
44: */
45: protected $_last;
46:
47: /**
48: * @access public
49: * @ignore
50: * @return string
51: */
52: public function get_last()
53: {
54: return $this->_last;
55: }
56:
57:
58:
59: /**
60: * @private
61: * @access protected
62: * @ignore
63: * @var string[]
64: */
65: protected $_asArray;
66:
67: /**
68: * @access public
69: * @ignore
70: * @return string[]
71: */
72: public function get_asArray()
73: {
74: $ret = new \ArrayObject([]);
75: $i = ip2long($this->_first);
76: $i1 = ip2long($this->_last);
77: while ($i <= $i1) {
78: $ret->append(long2ip($i));
79: $i++;
80: }
81: return $ret;
82: }
83:
84:
85:
86: /**
87: * @ignore
88: * @access public
89: * @param mixed $obj=null
90: */
91: public function __construct($obj=null)
92: {
93: if ($obj == null) {
94: $obj = (object)[];
95: }
96: $first = Util::getByPathAny(new \ArrayObject([$obj]), new \ArrayObject(["Min", "min"]));
97: $this->_first = null;
98: if ($first != null) {
99: $this->_first = $first;
100: }
101: if ($this->_first != null && $this->_first == "") {
102: $this->_first = null;
103: }
104: $last = Util::getByPathAny(new \ArrayObject([$obj]), new \ArrayObject(["Max", "max"]));
105: $this->_last = null;
106: if ($last != null) {
107: $this->_last = $last;
108: }
109: if ($this->_last != null && $this->_last == "") {
110: $this->_last = null;
111: }
112: }
113:
114: /**
115: * @ignore
116: */
117: public function __get($key) {
118: switch ($key) {
119: case "first": return $this->get_first();
120: case "last": return $this->get_last();
121: case "asArray": return $this->get_asArray();
122: default: return null;
123: }
124: }
125:
126: }
127:
128: