PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.2
Independent Analytics – WordPress Analytics Plugin v2.15.2
2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / mlocati / ip-lib / src / Range / Single.php
independent-analytics / vendor / mlocati / ip-lib / src / Range Last commit date
AbstractRange.php 2 weeks ago Pattern.php 2 weeks ago RangeInterface.php 2 weeks ago Single.php 2 weeks ago Subnet.php 2 weeks ago Type.php 2 weeks ago
Single.php
244 lines
1 <?php
2
3 namespace IAWPSCOPED\IPLib\Range;
4
5 use IAWPSCOPED\IPLib\Address\AddressInterface;
6 use IAWPSCOPED\IPLib\Address\IPv4;
7 use IAWPSCOPED\IPLib\Address\Type as AddressType;
8 use IAWPSCOPED\IPLib\Factory;
9 use IAWPSCOPED\IPLib\ParseStringFlag;
10 /**
11 * Represents a single address (eg a range that contains just one address).
12 *
13 * @example 127.0.0.1
14 * @example ::1
15 *
16 * @phpstan-consistent-constructor
17 * @internal
18 */
19 class Single extends AbstractRange
20 {
21 /**
22 * @var \IPLib\Address\AddressInterface
23 */
24 protected $address;
25 /**
26 * Initializes the instance.
27 *
28 * @param \IPLib\Address\AddressInterface $address
29 */
30 protected function __construct(AddressInterface $address)
31 {
32 $this->address = $address;
33 }
34 /**
35 * {@inheritdoc}
36 *
37 * @see \IPLib\Range\RangeInterface::__toString()
38 */
39 public function __toString()
40 {
41 return $this->address->__toString();
42 }
43 /**
44 * @deprecated since 1.17.0: use the parseString() method instead.
45 * For upgrading:
46 * - if $supportNonDecimalIPv4 is true, use the ParseStringFlag::IPV4_MAYBE_NON_DECIMAL flag
47 *
48 * @param string|mixed $range
49 * @param bool $supportNonDecimalIPv4
50 *
51 * @return static|null
52 *
53 * @see \IPLib\Range\Single::parseString()
54 * @since 1.10.0 added the $supportNonDecimalIPv4 argument
55 */
56 public static function fromString($range, $supportNonDecimalIPv4 = \false)
57 {
58 return static::parseString($range, ParseStringFlag::MAY_INCLUDE_PORT | ParseStringFlag::MAY_INCLUDE_ZONEID | ($supportNonDecimalIPv4 ? ParseStringFlag::IPV4_MAYBE_NON_DECIMAL : 0));
59 }
60 /**
61 * Try get the range instance starting from its string representation.
62 *
63 * @param string|mixed $range
64 * @param int $flags A combination or zero or more flags
65 *
66 * @return static|null
67 *
68 * @see \IPLib\ParseStringFlag
69 * @since 1.17.0
70 */
71 public static function parseString($range, $flags = 0)
72 {
73 $result = null;
74 $flags = (int) $flags;
75 $address = Factory::parseAddressString($range, $flags);
76 if ($address !== null) {
77 $result = new static($address);
78 }
79 return $result;
80 }
81 /**
82 * Create the range instance starting from an address instance.
83 *
84 * @param \IPLib\Address\AddressInterface $address
85 *
86 * @return static
87 *
88 * @since 1.2.0
89 */
90 public static function fromAddress(AddressInterface $address)
91 {
92 return new static($address);
93 }
94 /**
95 * {@inheritdoc}
96 *
97 * @see \IPLib\Range\RangeInterface::toString()
98 */
99 public function toString($long = \false)
100 {
101 return $this->address->toString($long);
102 }
103 /**
104 * {@inheritdoc}
105 *
106 * @see \IPLib\Range\RangeInterface::getAddressType()
107 */
108 public function getAddressType()
109 {
110 return $this->address->getAddressType();
111 }
112 /**
113 * {@inheritdoc}
114 *
115 * @see \IPLib\Range\RangeInterface::getRangeType()
116 */
117 public function getRangeType()
118 {
119 return $this->address->getRangeType();
120 }
121 /**
122 * {@inheritdoc}
123 *
124 * @see \IPLib\Range\RangeInterface::contains()
125 */
126 public function contains(AddressInterface $address)
127 {
128 $result = \false;
129 if ($address->getAddressType() === $this->getAddressType()) {
130 if ($address->toString(\false) === $this->address->toString(\false)) {
131 $result = \true;
132 }
133 }
134 return $result;
135 }
136 /**
137 * {@inheritdoc}
138 *
139 * @see \IPLib\Range\RangeInterface::getStartAddress()
140 */
141 public function getStartAddress()
142 {
143 return $this->address;
144 }
145 /**
146 * {@inheritdoc}
147 *
148 * @see \IPLib\Range\RangeInterface::getEndAddress()
149 */
150 public function getEndAddress()
151 {
152 return $this->address;
153 }
154 /**
155 * {@inheritdoc}
156 *
157 * @see \IPLib\Range\RangeInterface::getComparableStartString()
158 */
159 public function getComparableStartString()
160 {
161 return $this->address->getComparableString();
162 }
163 /**
164 * {@inheritdoc}
165 *
166 * @see \IPLib\Range\RangeInterface::getComparableEndString()
167 */
168 public function getComparableEndString()
169 {
170 return $this->address->getComparableString();
171 }
172 /**
173 * {@inheritdoc}
174 *
175 * @see \IPLib\Range\RangeInterface::asSubnet()
176 */
177 public function asSubnet()
178 {
179 return new Subnet($this->address, $this->address, $this->getNetworkPrefix());
180 }
181 /**
182 * {@inheritdoc}
183 *
184 * @see \IPLib\Range\RangeInterface::asPattern()
185 */
186 public function asPattern()
187 {
188 return new Pattern($this->address, $this->address, 0);
189 }
190 /**
191 * {@inheritdoc}
192 *
193 * @see \IPLib\Range\RangeInterface::getSubnetMask()
194 */
195 public function getSubnetMask()
196 {
197 if ($this->getAddressType() !== AddressType::T_IPv4) {
198 return null;
199 }
200 return IPv4::fromBytes(array(255, 255, 255, 255));
201 }
202 /**
203 * {@inheritdoc}
204 *
205 * @see \IPLib\Range\RangeInterface::getReverseDNSLookupName()
206 */
207 public function getReverseDNSLookupName()
208 {
209 return array($this->getStartAddress()->getReverseDNSLookupName());
210 }
211 /**
212 * {@inheritdoc}
213 *
214 * @see \IPLib\Range\RangeInterface::getSize()
215 */
216 public function getSize()
217 {
218 return 1;
219 }
220 /**
221 * {@inheritdoc}
222 *
223 * @see \IPLib\Range\RangeInterface::getExactSize()
224 */
225 public function getExactSize()
226 {
227 return 1;
228 }
229 /**
230 * {@inheritdoc}
231 *
232 * @see \IPLib\Range\RangeInterface::getNetworkPrefix()
233 */
234 public function getNetworkPrefix()
235 {
236 switch ($this->getAddressType()) {
237 case AddressType::T_IPv4:
238 return 32;
239 case AddressType::T_IPv6:
240 return 128;
241 }
242 }
243 }
244