@@ -114,14 +114,14 @@ public static function buildUrl($url, $mixed_data = '')
114
114
*/
115
115
private function absolutizeUrl ()
116
116
{
117
- $ b = $ this -> parseUrl ($ this ->baseUrl );
117
+ $ b = self :: parseUrl ($ this ->baseUrl );
118
118
if (!isset ($ b ['path ' ])) {
119
119
$ b ['path ' ] = '/ ' ;
120
120
}
121
121
if ($ this ->relativeUrl === null ) {
122
122
return $ this ->unparseUrl ($ b );
123
123
}
124
- $ r = $ this -> parseUrl ($ this ->relativeUrl );
124
+ $ r = self :: parseUrl ($ this ->relativeUrl );
125
125
$ r ['authorized ' ] = isset ($ r ['scheme ' ]) || isset ($ r ['host ' ]) || isset ($ r ['port ' ])
126
126
|| isset ($ r ['user ' ]) || isset ($ r ['pass ' ]);
127
127
$ target = [];
@@ -178,58 +178,11 @@ private function absolutizeUrl()
178
178
*
179
179
* Parse url into components of a URI as specified by RFC 3986.
180
180
*/
181
- private function parseUrl ($ url )
181
+ public static function parseUrl ($ url )
182
182
{
183
- // RFC 3986 - Parsing a URI Reference with a Regular Expression.
184
- // ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
185
- // 12 3 4 5 6 7 8 9
186
- //
187
- // "http://www.ics.uci.edu/pub/ietf/uri/#Related"
188
- // $1 = http: (scheme)
189
- // $2 = http (scheme)
190
- // $3 = //www.ics.uci.edu (ignore)
191
- // $4 = www.ics.uci.edu (authority)
192
- // $5 = /pub/ietf/uri/ (path)
193
- // $6 = <undefined> (ignore)
194
- // $7 = <undefined> (query)
195
- // $8 = #Related (ignore)
196
- // $9 = Related (fragment)
197
- preg_match ('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/ ' , (string ) $ url , $ output_array );
198
-
199
- $ parts = [];
200
- if (isset ($ output_array ['1 ' ]) && $ output_array ['1 ' ] !== '' ) {
201
- $ parts ['scheme ' ] = $ output_array ['1 ' ];
202
- }
203
- if (isset ($ output_array ['2 ' ]) && $ output_array ['2 ' ] !== '' ) {
204
- $ parts ['scheme ' ] = $ output_array ['2 ' ];
205
- }
206
- if (isset ($ output_array ['4 ' ]) && $ output_array ['4 ' ] !== '' ) {
207
- // authority = [ userinfo "@" ] host [ ":" port ]
208
- $ parts ['host ' ] = $ output_array ['4 ' ];
209
- if (strpos ($ parts ['host ' ], ': ' ) !== false ) {
210
- $ host_parts = explode (': ' , $ output_array ['4 ' ]);
211
- $ parts ['port ' ] = array_pop ($ host_parts );
212
- $ parts ['host ' ] = implode (': ' , $ host_parts );
213
- if (strpos ($ parts ['host ' ], '@ ' ) !== false ) {
214
- $ host_parts = explode ('@ ' , $ parts ['host ' ]);
215
- $ parts ['host ' ] = array_pop ($ host_parts );
216
- $ parts ['user ' ] = implode ('@ ' , $ host_parts );
217
- if (strpos ($ parts ['user ' ], ': ' ) !== false ) {
218
- $ user_parts = explode (': ' , $ parts ['user ' ], 2 );
219
- $ parts ['user ' ] = array_shift ($ user_parts );
220
- $ parts ['pass ' ] = implode (': ' , $ user_parts );
221
- }
222
- }
223
- }
224
- }
225
- if (isset ($ output_array ['5 ' ]) && $ output_array ['5 ' ] !== '' ) {
226
- $ parts ['path ' ] = $ this ->percentEncodeChars ($ output_array ['5 ' ]);
227
- }
228
- if (isset ($ output_array ['7 ' ]) && $ output_array ['7 ' ] !== '' ) {
229
- $ parts ['query ' ] = $ output_array ['7 ' ];
230
- }
231
- if (isset ($ output_array ['9 ' ]) && $ output_array ['9 ' ] !== '' ) {
232
- $ parts ['fragment ' ] = $ output_array ['9 ' ];
183
+ $ parts = parse_url ((string ) $ url );
184
+ if (isset ($ parts ['path ' ])) {
185
+ $ parts ['path ' ] = self ::percentEncodeChars ($ parts ['path ' ]);
233
186
}
234
187
return $ parts ;
235
188
}
@@ -240,7 +193,7 @@ private function parseUrl($url)
240
193
* Percent-encode characters to represent a data octet in a component when
241
194
* that octet's corresponding character is outside the allowed set.
242
195
*/
243
- private function percentEncodeChars ($ chars )
196
+ private static function percentEncodeChars ($ chars )
244
197
{
245
198
// ALPHA = A-Z / a-z
246
199
$ alpha = 'A-Za-z ' ;
0 commit comments