1
|
|
|
<?php |
2
|
|
|
namespace Subreality\Dilmun\Anshar\Http\UriParts; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class UserInfo |
6
|
|
|
* @package Subreality\Dilmun\Anshar\Http\UriParts |
7
|
|
|
*/ |
8
|
|
|
class UserInfo extends AbstractUriPart |
9
|
|
|
{ |
10
|
|
|
protected $unencoded_characters = array(":"); |
11
|
|
|
protected $compositions = array( |
12
|
|
|
"unreserved_characters", |
13
|
|
|
"sub_delims_characters", |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* UserInfo constructor. Accepts a string representing a URI user info component. Construction will throw an |
18
|
|
|
* exception if the user info is not a string. |
19
|
|
|
* |
20
|
|
|
* Construction accepts strings that have been percent-encoded as well as strings that have not been percent-encoded |
21
|
|
|
* and will encode invalid characters. |
22
|
|
|
* |
23
|
|
|
* Construction with a string that includes both encoded and decoded characters will be assumed to be an encoded |
24
|
|
|
* string, resulting in double-encoding. |
25
|
|
|
* |
26
|
|
|
* userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) |
27
|
|
|
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" |
28
|
|
|
* pct-encoded = "%" HEXDIG HEXDIG |
29
|
|
|
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" |
30
|
|
|
* |
31
|
|
|
* @see https://tools.ietf.org/html/rfc3986#appendix-A |
32
|
|
|
* |
33
|
|
|
* @throws \InvalidArgumentException |
34
|
|
|
* |
35
|
|
|
* @param string $user_info A string representing a URI fragment |
36
|
|
|
*/ |
37
|
18 |
|
public function __construct($user_info) |
38
|
|
|
{ |
39
|
18 |
|
parent::__construct($user_info, "User info"); |
40
|
12 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns a string representation of the user info formatted so that it can be compiled into a complete URI string |
44
|
|
|
* per the Uri object's string specification. |
45
|
|
|
* |
46
|
|
|
* If user info is empty, toUriString returns an empty string; if user info is not empty, toUriString returns |
47
|
|
|
* the user info suffixed with an at(@). |
48
|
|
|
* |
49
|
|
|
* @see Uri::__toString |
50
|
|
|
* |
51
|
|
|
* @return string A string representation of the user info formatted for a complete URI string |
52
|
|
|
*/ |
53
|
2 |
|
public function toUriString() |
54
|
|
|
{ |
55
|
2 |
|
$uri_userinfo = parent::toUriString(); //returns data string |
56
|
|
|
|
57
|
2 |
|
if (!empty($uri_userinfo)) { |
58
|
1 |
|
$uri_userinfo = $uri_userinfo . "@"; |
59
|
1 |
|
} |
60
|
|
|
|
61
|
2 |
|
return $uri_userinfo; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|