|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* apparat-object |
|
5
|
|
|
* |
|
6
|
|
|
* @category Apparat |
|
7
|
|
|
* @package Apparat\Object |
|
8
|
|
|
* @subpackage Apparat\Object\Domain |
|
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
|
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
|
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/*********************************************************************************** |
|
15
|
|
|
* The MIT License (MIT) |
|
16
|
|
|
* |
|
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
|
18
|
|
|
* |
|
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
|
21
|
|
|
* the Software without restriction, including without limitation the rights to |
|
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
|
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
|
24
|
|
|
* subject to the following conditions: |
|
25
|
|
|
* |
|
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
27
|
|
|
* copies or substantial portions of the Software. |
|
28
|
|
|
* |
|
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
35
|
|
|
***********************************************************************************/ |
|
36
|
|
|
|
|
37
|
|
|
namespace Apparat\Object\Domain\Model\Path\Traits; |
|
38
|
|
|
|
|
39
|
|
|
use Apparat\Object\Domain\Model\Path\Url; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* PSR-7 URI trait |
|
43
|
|
|
* |
|
44
|
|
|
* @package Apparat\Object\Domain\Model\Path\Traits |
|
45
|
|
|
* @method Url setUser() |
|
46
|
|
|
*/ |
|
47
|
|
|
trait Psr7Trait |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* Return the URL path |
|
51
|
|
|
* |
|
52
|
|
|
* @return string URL path |
|
53
|
|
|
*/ |
|
54
|
34 |
|
public function getPath() |
|
55
|
|
|
{ |
|
56
|
34 |
|
return $this->urlParts['path']; |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Return the URL host |
|
61
|
|
|
* |
|
62
|
|
|
* @return string URL host |
|
63
|
|
|
*/ |
|
64
|
31 |
|
public function getHost() |
|
65
|
|
|
{ |
|
66
|
31 |
|
return isset($this->urlParts['host']) ? $this->urlParts['host'] : null; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Return the URL port |
|
71
|
|
|
* |
|
72
|
|
|
* @return int URL port |
|
73
|
|
|
*/ |
|
74
|
11 |
|
public function getPort() |
|
75
|
|
|
{ |
|
76
|
11 |
|
return isset($this->urlParts['port']) ? $this->urlParts['port'] : null; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Return the URL fragment |
|
81
|
|
|
* |
|
82
|
|
|
* @return string URL fragment |
|
83
|
|
|
*/ |
|
84
|
11 |
|
public function getFragment() |
|
85
|
|
|
{ |
|
86
|
11 |
|
return isset($this->urlParts['fragment']) ? $this->urlParts['fragment'] : null; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Return the URL query |
|
91
|
|
|
* |
|
92
|
|
|
* @return array URL query |
|
93
|
|
|
*/ |
|
94
|
7 |
|
public function getQuery() |
|
95
|
|
|
{ |
|
96
|
7 |
|
return isset($this->urlParts['query']) ? $this->urlParts['query'] : ''; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Return the URL scheme |
|
101
|
|
|
* |
|
102
|
|
|
* @return string URL scheme |
|
103
|
|
|
*/ |
|
104
|
31 |
|
public function getScheme() |
|
105
|
|
|
{ |
|
106
|
31 |
|
return isset($this->urlParts['scheme']) ? $this->urlParts['scheme'] : null; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Return the URL authority |
|
111
|
|
|
* |
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function getAuthority() |
|
115
|
|
|
{ |
|
116
|
1 |
|
$uriParts = []; |
|
117
|
1 |
|
$this->getUrlInternal($uriParts); |
|
|
|
|
|
|
118
|
1 |
|
return $uriParts['user'].$uriParts['pass'].$uriParts['host'].$uriParts['port']; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Return the URL user info |
|
123
|
|
|
* |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function getUserInfo() |
|
127
|
|
|
{ |
|
128
|
1 |
|
$uriParts = []; |
|
129
|
1 |
|
$this->getUrlInternal($uriParts); |
|
|
|
|
|
|
130
|
1 |
|
return rtrim($uriParts['user'].$uriParts['pass'], '@'); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Return an instance of this URL with the given scheme |
|
135
|
|
|
* |
|
136
|
|
|
* @param string $scheme Scheme |
|
137
|
|
|
* @return Url Instance with the given scheme |
|
138
|
|
|
*/ |
|
139
|
1 |
|
public function withScheme($scheme) |
|
140
|
|
|
{ |
|
141
|
1 |
|
return $this->setScheme($scheme); |
|
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Return an instance of this URL with the given user info |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $user User name |
|
148
|
|
|
* @param string|null $password Password |
|
149
|
|
|
* @return Url URL instance with given user info |
|
150
|
|
|
*/ |
|
151
|
1 |
|
public function withUserInfo($user, $password = null) |
|
152
|
|
|
{ |
|
153
|
1 |
|
return $this->setUser($user)->setPassword($password); |
|
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Return an instance of this URL with the given host |
|
158
|
|
|
* |
|
159
|
|
|
* @param string $host Host |
|
160
|
|
|
* @return Url Instance with the given host |
|
161
|
|
|
*/ |
|
162
|
1 |
|
public function withHost($host) |
|
163
|
|
|
{ |
|
164
|
1 |
|
return $this->setHost($host); |
|
|
|
|
|
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Return an instance of this URL with the given port |
|
169
|
|
|
* |
|
170
|
|
|
* @param null|int $port Port |
|
171
|
|
|
* @return Url Instance with the given port |
|
172
|
|
|
*/ |
|
173
|
1 |
|
public function withPort($port) |
|
174
|
|
|
{ |
|
175
|
1 |
|
return $this->setPort($port); |
|
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Return an instance of this URL with the given path |
|
180
|
|
|
* |
|
181
|
|
|
* @param null|int $path Path |
|
182
|
|
|
* @return Url Instance with the given path |
|
183
|
|
|
*/ |
|
184
|
1 |
|
public function withPath($path) |
|
185
|
|
|
{ |
|
186
|
1 |
|
return $this->setPath($path); |
|
|
|
|
|
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Return an instance of this URL with the given query |
|
191
|
|
|
* |
|
192
|
|
|
* @param null|string $query Query |
|
193
|
|
|
* @return Url Instance with the given query |
|
194
|
|
|
*/ |
|
195
|
1 |
|
public function withQuery($query) |
|
196
|
|
|
{ |
|
197
|
1 |
|
return $this->setQuery($query); |
|
|
|
|
|
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Return an instance of this URL with the given fragment |
|
202
|
|
|
* |
|
203
|
|
|
* @param null|int $fragment Fragment |
|
204
|
|
|
* @return Url Instance with the given fragment |
|
205
|
|
|
*/ |
|
206
|
1 |
|
public function withFragment($fragment) |
|
207
|
|
|
{ |
|
208
|
1 |
|
return $this->setFragment($fragment); |
|
|
|
|
|
|
209
|
|
|
} |
|
210
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: