1 | <?php |
||
26 | class Url extends Datawrapper\Base |
||
27 | { |
||
28 | /** |
||
29 | * All the parts from the url are stored separetely even after treated, |
||
30 | * this will allow to change specific bits without the need to rebuild the |
||
31 | * entire url |
||
32 | * |
||
33 | * @var associative array |
||
34 | */ |
||
35 | private $fullUrl = [ |
||
36 | 'scheme' => '', |
||
37 | 'credentials' => '', |
||
38 | 'host' => '', |
||
39 | 'port' => '', |
||
40 | 'path' => '', |
||
41 | 'query' => '', |
||
42 | 'fragment' => '' |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | private $scheme; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | private $host; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | private $port; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | private $user; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | */ |
||
68 | private $pass; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | private $path = []; |
||
74 | |||
75 | /** |
||
76 | * Associative array to build query string |
||
77 | * |
||
78 | * @var array |
||
79 | */ |
||
80 | private $query = []; |
||
81 | |||
82 | /** |
||
83 | * @var string |
||
84 | */ |
||
85 | private $fragment; |
||
86 | |||
87 | /** |
||
88 | * Build the final url based on the structure defined |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | 5 | public function getFullUrl() |
|
106 | |||
107 | /** |
||
108 | * Add host to the final url |
||
109 | * |
||
110 | * @param string $host |
||
111 | * @return Url |
||
112 | */ |
||
113 | 4 | public function addHost($host) |
|
118 | |||
119 | /** |
||
120 | * Add port to the final url |
||
121 | * |
||
122 | * @param string $port |
||
123 | * @return Url |
||
124 | */ |
||
125 | 3 | public function addPort($port) |
|
130 | |||
131 | /** |
||
132 | * Add scheme to the final url |
||
133 | * |
||
134 | * @param string $scheme |
||
135 | * @return Url |
||
136 | */ |
||
137 | 4 | public function addScheme($scheme) |
|
142 | |||
143 | /** |
||
144 | * Add the credentials to the final url, both username and password are |
||
145 | * added in this stage |
||
146 | * |
||
147 | * @param string $user |
||
148 | * @return Url |
||
149 | */ |
||
150 | 3 | public function addUser($user) |
|
159 | |||
160 | /** |
||
161 | * Add paths to the final url |
||
162 | * |
||
163 | * @param string $path |
||
164 | * @return Url |
||
165 | */ |
||
166 | 5 | public function addPath($path) |
|
171 | |||
172 | /** |
||
173 | * Add query string to the final url |
||
174 | * |
||
175 | * @param array $query |
||
176 | * @return Url |
||
177 | */ |
||
178 | 3 | public function addQuery(array $query) |
|
189 | |||
190 | /** |
||
191 | * Add fragment to the final url |
||
192 | * |
||
193 | * @param string $fragment |
||
194 | * @return Url |
||
195 | */ |
||
196 | 3 | public function addFragment($fragment) |
|
201 | |||
202 | /** |
||
203 | * Replace path values |
||
204 | * |
||
205 | * @param associative array $replace |
||
206 | * @return Url |
||
207 | */ |
||
208 | 2 | public function replacePath(array $replace) |
|
212 | |||
213 | /** |
||
214 | * Replace query string values |
||
215 | * |
||
216 | * @param associative array $replace |
||
217 | * @return Url |
||
218 | */ |
||
219 | 1 | public function replaceQuery(array $replace) |
|
223 | } |
||
224 |