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