pradosoft /
prado
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * THttpRequest, THttpCookie, THttpCookieCollection, TUri class file |
||
| 5 | * |
||
| 6 | * @author Qiang Xue <[email protected]> |
||
| 7 | * @link https://github.com/pradosoft/prado |
||
| 8 | * @license https://github.com/pradosoft/prado/blob/master/LICENSE |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Prado\Web; |
||
| 12 | |||
| 13 | use Prado\Exceptions\TInvalidDataValueException; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * TUri class |
||
| 17 | * |
||
| 18 | * TUri represents a URI. Given a URI |
||
| 19 | * http://joe:[email protected]:8080/path/to/script.php?param=value#anchor |
||
| 20 | * it will be decomposed as follows, |
||
| 21 | * - scheme: http |
||
| 22 | * - host: example.com |
||
| 23 | * - port: 8080 |
||
| 24 | * - user: joe |
||
| 25 | * - password: whatever |
||
| 26 | * - path: /path/to/script.php |
||
| 27 | * - query: param=value |
||
| 28 | * - fragment: anchor |
||
| 29 | * |
||
| 30 | * @author Qiang Xue <[email protected]> |
||
| 31 | * @since 3.0 |
||
| 32 | */ |
||
| 33 | class TUri extends \Prado\TComponent |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var array list of default ports for known schemes |
||
| 37 | */ |
||
| 38 | private static $_defaultPort = [ |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 39 | 'ftp' => 21, |
||
| 40 | 'gopher' => 70, |
||
| 41 | 'http' => 80, |
||
| 42 | 'https' => 443, |
||
| 43 | 'news' => 119, |
||
| 44 | 'nntp' => 119, |
||
| 45 | 'wais' => 210, |
||
| 46 | 'telnet' => 23, |
||
| 47 | ]; |
||
| 48 | /** |
||
| 49 | * @var string scheme of the URI |
||
| 50 | */ |
||
| 51 | private $_scheme; |
||
| 52 | /** |
||
| 53 | * @var string host name of the URI |
||
| 54 | */ |
||
| 55 | private $_host; |
||
| 56 | /** |
||
| 57 | * @var int port of the URI |
||
| 58 | */ |
||
| 59 | private $_port; |
||
| 60 | /** |
||
| 61 | * @var string user of the URI |
||
| 62 | */ |
||
| 63 | private $_user; |
||
| 64 | /** |
||
| 65 | * @var string password of the URI |
||
| 66 | */ |
||
| 67 | private $_pass; |
||
| 68 | /** |
||
| 69 | * @var string path of the URI |
||
| 70 | */ |
||
| 71 | private $_path; |
||
| 72 | /** |
||
| 73 | * @var string query string of the URI |
||
| 74 | */ |
||
| 75 | private $_query; |
||
| 76 | /** |
||
| 77 | * @var string fragment of the URI |
||
| 78 | */ |
||
| 79 | private $_fragment; |
||
| 80 | /** |
||
| 81 | * @var string the URI |
||
| 82 | */ |
||
| 83 | private $_uri; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Constructor. |
||
| 87 | * Decomposes the specified URI into parts. |
||
| 88 | * @param string $uri URI to be represented |
||
| 89 | * @throws TInvalidDataValueException if URI is of bad format |
||
| 90 | */ |
||
| 91 | public function __construct($uri) |
||
| 92 | 13 | { |
|
| 93 | if (($ret = @parse_url($uri)) !== false) { |
||
| 94 | 13 | // decoding??? |
|
| 95 | $this->_scheme = $ret['scheme'] ?? ''; |
||
| 96 | 13 | $this->_host = $ret['host'] ?? ''; |
|
| 97 | 13 | $this->_port = $ret['port'] ?? ''; |
|
|
0 ignored issues
–
show
It seems like
$ret['port'] ?? '' can also be of type string. However, the property $_port is declared as type integer. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
| 98 | 13 | $this->_user = $ret['user'] ?? ''; |
|
| 99 | 13 | $this->_pass = $ret['pass'] ?? ''; |
|
| 100 | 13 | $this->_path = $ret['path'] ?? ''; |
|
| 101 | 13 | $this->_query = $ret['query'] ?? ''; |
|
| 102 | 13 | $this->_fragment = $ret['fragment'] ?? ''; |
|
| 103 | 13 | $this->_uri = $uri; |
|
| 104 | 13 | } else { |
|
| 105 | throw new TInvalidDataValueException('uri_format_invalid', $uri); |
||
| 106 | 1 | } |
|
| 107 | parent::__construct(); |
||
| 108 | 13 | } |
|
| 109 | |||
| 110 | /** |
||
| 111 | * @return string URI |
||
| 112 | */ |
||
| 113 | 2 | public function getUri() |
|
| 114 | { |
||
| 115 | 2 | return $this->_uri; |
|
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @return string scheme of the URI, such as 'http', 'https', 'ftp', etc. |
||
| 120 | */ |
||
| 121 | 3 | public function getScheme() |
|
| 122 | { |
||
| 123 | 3 | return $this->_scheme; |
|
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @return string hostname of the URI |
||
| 128 | */ |
||
| 129 | 3 | public function getHost() |
|
| 130 | { |
||
| 131 | 3 | return $this->_host; |
|
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return int port number of the URI |
||
| 136 | */ |
||
| 137 | 3 | public function getPort() |
|
| 138 | { |
||
| 139 | 3 | return $this->_port; |
|
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return string username of the URI |
||
| 144 | */ |
||
| 145 | 1 | public function getUser() |
|
| 146 | { |
||
| 147 | 1 | return $this->_user; |
|
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return string password of the URI |
||
| 152 | */ |
||
| 153 | 1 | public function getPassword() |
|
| 154 | { |
||
| 155 | 1 | return $this->_pass; |
|
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @return string path of the URI |
||
| 160 | */ |
||
| 161 | 1 | public function getPath() |
|
| 162 | { |
||
| 163 | 1 | return $this->_path; |
|
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return string query string of the URI |
||
| 168 | */ |
||
| 169 | 1 | public function getQuery() |
|
| 170 | { |
||
| 171 | 1 | return $this->_query; |
|
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @return string fragment of the URI |
||
| 176 | */ |
||
| 177 | 1 | public function getFragment() |
|
| 178 | { |
||
| 179 | 1 | return $this->_fragment; |
|
| 180 | } |
||
| 181 | } |
||
| 182 |