|
1
|
|
|
<?php |
|
2
|
|
|
namespace Subreality\Dilmun\Anshar\Http\UriParts; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class Authority |
|
6
|
|
|
* @package Subreality\Dilmun\Anshar\Http\UriParts |
|
7
|
|
|
*/ |
|
8
|
|
|
class Authority extends AbstractUriPart |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var UserInfo */ |
|
11
|
|
|
protected $user_info; |
|
12
|
|
|
/** @var Host */ |
|
13
|
|
|
protected $host; |
|
14
|
|
|
/** @var Port */ |
|
15
|
|
|
protected $port; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Authority constructor. Accepts a string representing a URI authority component. Construction will throw an |
|
19
|
|
|
* exception if the authority is not a string. |
|
20
|
|
|
* |
|
21
|
|
|
* Construction splits a given authority string into its component objects, UserInfo, Host, and Port, whose |
|
22
|
|
|
* individual constructors may throw exceptions provided invalid component strings. |
|
23
|
|
|
* |
|
24
|
|
|
* Construction accepts strings for UserInfo and Host that have been percent-encoded as well as strings that have |
|
25
|
|
|
* not been percent-encoded and will encode invalid characters. |
|
26
|
|
|
* |
|
27
|
|
|
* Construction with a string that includes both encoded and decoded characters will be assumed to be an encoded |
|
28
|
|
|
* string, resulting in double-encoding. |
|
29
|
|
|
* |
|
30
|
|
|
* authority = [ userinfo "@" ] host [ ":" port ] |
|
31
|
|
|
* |
|
32
|
|
|
* @see UserInfo |
|
33
|
|
|
* @see Host |
|
34
|
|
|
* @see Port |
|
35
|
|
|
* @see https://tools.ietf.org/html/rfc3986#appendix-A |
|
36
|
|
|
* |
|
37
|
|
|
* @throws \InvalidArgumentException given a non-string |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $authority A string representing a URI authority |
|
40
|
|
|
*/ |
|
41
|
6 |
|
public function __construct($authority) |
|
42
|
|
|
{ |
|
43
|
6 |
|
$this->user_info = new UserInfo(""); |
|
44
|
6 |
|
$this->host = new Host(""); |
|
45
|
6 |
|
$this->port = new Port(null); |
|
46
|
|
|
|
|
47
|
6 |
|
parent::__construct($authority, "Authority"); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns the authority's UserInfo object |
|
52
|
|
|
* |
|
53
|
|
|
* @return UserInfo |
|
54
|
|
|
*/ |
|
55
|
2 |
|
public function getUserInfo() |
|
56
|
|
|
{ |
|
57
|
2 |
|
return $this->user_info; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the authority's Host object |
|
62
|
|
|
* |
|
63
|
|
|
* @return Host |
|
64
|
|
|
*/ |
|
65
|
2 |
|
public function getHost() |
|
66
|
|
|
{ |
|
67
|
2 |
|
return $this->host; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the authority's Port object |
|
72
|
|
|
* |
|
73
|
|
|
* @return Port |
|
74
|
|
|
*/ |
|
75
|
2 |
|
public function getPort() |
|
76
|
|
|
{ |
|
77
|
2 |
|
return $this->port; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|