| 1 |
<?php |
| 2 |
|
| 3 |
class Red_Url_Match { |
| 4 |
private $url; |
| 5 |
|
| 6 |
public function __construct( $url ) { |
| 7 |
$this->url = $url; |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* Get the plain 'matched' URL: |
| 12 |
* |
| 13 |
* - Lowercase |
| 14 |
* - No trailing slashes |
| 15 |
* |
| 16 |
* @return string URL |
| 17 |
*/ |
| 18 |
public function get_url() { |
| 19 |
// Remove query params, and decode any encoded characters |
| 20 |
$url = new Red_Url_Path( $this->url ); |
| 21 |
$path = $url->get_without_trailing_slash(); |
| 22 |
|
| 23 |
// URL encode |
| 24 |
$decode = [ |
| 25 |
'/', |
| 26 |
':', |
| 27 |
'[', |
| 28 |
']', |
| 29 |
'@', |
| 30 |
'~', |
| 31 |
',', |
| 32 |
'(', |
| 33 |
')', |
| 34 |
';', |
| 35 |
]; |
| 36 |
|
| 37 |
// URL encode everything - this converts any i10n to the proper encoding |
| 38 |
$path = rawurlencode( $path ); |
| 39 |
|
| 40 |
// We also converted things we dont want encoding, such as a /. Change these back |
| 41 |
foreach ( $decode as $char ) { |
| 42 |
$path = str_replace( rawurlencode( $char ), $char, $path ); |
| 43 |
} |
| 44 |
|
| 45 |
// Lowercase everything |
| 46 |
$path = Red_Url_Path::to_lower( $path ); |
| 47 |
|
| 48 |
return $path ? $path : '/'; |
| 49 |
} |
| 50 |
} |
| 51 |
|