1
1
<?php
2
2
3
3
/**
4
- * PHP Domain Parser: Public Suffix List based URL parsing.
4
+ * PHP Domain Parser: Public Suffix List based URL parsing
5
5
*
6
6
* @link http://github.com/jeremykendall/php-domain-parser for the canonical source repository
7
- *
8
7
* @copyright Copyright (c) 2014 Jeremy Kendall (http://about.me/jeremykendall)
9
8
* @license http://github.com/jeremykendall/php-domain-parser/blob/master/LICENSE MIT License
10
9
*/
11
-
12
10
namespace Pdp ;
13
11
14
12
use Pdp \Uri \Url ;
15
13
use Pdp \Uri \Url \Host ;
16
14
17
15
/**
18
- * Parser.
16
+ * Parser
19
17
*
20
18
* This class is reponsible for Public Suffix List based url parsing
21
19
*/
@@ -35,10 +33,9 @@ class Parser
35
33
protected $ isNormalized = false ;
36
34
37
35
/**
38
- * Public constructor.
36
+ * Public constructor
39
37
*
40
38
* @codeCoverageIgnore
41
- *
42
39
* @param PublicSuffixList $publicSuffixList Instance of PublicSuffixList
43
40
*/
44
41
public function __construct (PublicSuffixList $ publicSuffixList )
@@ -47,11 +44,10 @@ public function __construct(PublicSuffixList $publicSuffixList)
47
44
}
48
45
49
46
/**
50
- * Parses url.
51
- *
52
- * @param string $url Url to parse
47
+ * Parses url
53
48
*
54
- * @return Url Object representation of url
49
+ * @param string $url Url to parse
50
+ * @return Url Object representation of url
55
51
*/
56
52
public function parseUrl ($ url )
57
53
{
@@ -93,11 +89,10 @@ public function parseUrl($url)
93
89
}
94
90
95
91
/**
96
- * Parses host part of url.
92
+ * Parses host part of url
97
93
*
98
- * @param string $host Host part of url
99
- *
100
- * @return Host Object representation of host portion of url
94
+ * @param string $host Host part of url
95
+ * @return Host Object representation of host portion of url
101
96
*/
102
97
public function parseHost ($ host )
103
98
{
@@ -126,10 +121,9 @@ public function parseHost($host)
126
121
127
122
/**
128
123
* Get the raw public suffix based on the cached public suffix list file.
129
- * Return false if the provided suffix is not included in the PSL.
130
- *
131
- * @param string $host The host to process
124
+ * Return false if the provided suffix is not included in the PSL
132
125
*
126
+ * @param string $host The host to process
133
127
* @return string|false The suffix or false if suffix not included in the PSL
134
128
*/
135
129
protected function getRawPublicSuffix ($ host )
@@ -179,10 +173,9 @@ protected function getRawPublicSuffix($host)
179
173
}
180
174
181
175
/**
182
- * Returns the public suffix portion of provided host.
183
- *
184
- * @param string $host host
176
+ * Returns the public suffix portion of provided host
185
177
*
178
+ * @param string $host host
186
179
* @return string|null public suffix or null if host does not contain a public suffix
187
180
*/
188
181
public function getPublicSuffix ($ host )
@@ -219,24 +212,22 @@ public function getPublicSuffix($host)
219
212
*
220
213
* Validity determined by whether or not the suffix is included in the PSL.
221
214
*
222
- * @param string $host Host part
223
- *
224
- * @return bool True is suffix is valid, false otherwise
215
+ * @param string $host Host part
216
+ * @return bool True is suffix is valid, false otherwise
225
217
*/
226
218
public function isSuffixValid ($ host )
227
219
{
228
220
return $ this ->getRawPublicSuffix ($ host ) !== false ;
229
221
}
230
222
231
223
/**
232
- * Returns registerable domain portion of provided host.
224
+ * Returns registerable domain portion of provided host
233
225
*
234
226
* Per the test cases provided by Mozilla
235
227
* (http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1),
236
228
* this method should return null if the domain provided is a public suffix.
237
229
*
238
- * @param string $host host
239
- *
230
+ * @param string $host host
240
231
* @return string registerable domain
241
232
*/
242
233
public function getRegisterableDomain ($ host )
@@ -259,10 +250,9 @@ public function getRegisterableDomain($host)
259
250
}
260
251
261
252
/**
262
- * Returns the subdomain portion of provided host.
263
- *
264
- * @param string $host host
253
+ * Returns the subdomain portion of provided host
265
254
*
255
+ * @param string $host host
266
256
* @return string subdomain
267
257
*/
268
258
public function getSubdomain ($ host )
@@ -289,8 +279,7 @@ public function getSubdomain($host)
289
279
* If a URL is not punycoded, then it may be an IDNA URL, so it must be
290
280
* converted to ASCII. Performs conversion and sets flag.
291
281
*
292
- * @param string $part Host part
293
- *
282
+ * @param string $part Host part
294
283
* @return string Host part, transformed if not punycoded
295
284
*/
296
285
protected function normalize ($ part )
@@ -309,8 +298,7 @@ protected function normalize($part)
309
298
* Converts any normalized part back to IDNA. Performs conversion and
310
299
* resets flag.
311
300
*
312
- * @param string $part Host part
313
- *
301
+ * @param string $part Host part
314
302
* @return string Denormalized host part
315
303
*/
316
304
protected function denormalize ($ part )
@@ -324,27 +312,25 @@ protected function denormalize($part)
324
312
}
325
313
326
314
/**
327
- * Tests host for presence of '.'.
315
+ * Tests host for presence of '.'
328
316
*
329
317
* Related to #22
330
318
*
331
- * @param string $host Host part of url
332
- *
333
- * @return bool True if multi-label domain, false otherwise
319
+ * @param string $host Host part of url
320
+ * @return bool True if multi-label domain, false otherwise
334
321
*/
335
322
protected function isMutliLabelDomain ($ host )
336
323
{
337
324
return strpos ($ host , '. ' ) !== false ;
338
325
}
339
326
340
327
/**
341
- * Tests host to determine if it is an IP address.
328
+ * Tests host to determine if it is an IP address
342
329
*
343
330
* Related to #43
344
331
*
345
- * @param string $host Host part of url
346
- *
347
- * @return bool True if host is an ip address, false otherwise
332
+ * @param string $host Host part of url
333
+ * @return bool True if host is an ip address, false otherwise
348
334
*/
349
335
protected function isIpv4Address ($ host )
350
336
{
0 commit comments