| 1 |
<?php |
| 2 |
|
| 3 |
class Red_Url_Path { |
| 4 |
public function __construct( $url ) { |
| 5 |
$this->path = $this->get_url_path( $url ); |
| 6 |
} |
| 7 |
|
| 8 |
private function get_url_path( $url ) { |
| 9 |
$path = wp_parse_url( $url, PHP_URL_PATH ); |
| 10 |
|
| 11 |
return $path ? $path : '/'; |
| 12 |
} |
| 13 |
|
| 14 |
public function is_match( $url, Red_Source_Flags $flags ) { |
| 15 |
$source = $this->path; |
| 16 |
$target = $this->get_url_path( $url ); |
| 17 |
|
| 18 |
if ( $flags->is_ignore_case() ) { |
| 19 |
// Case insensitive match |
| 20 |
$source = strtolower( $source ); |
| 21 |
$target = strtolower( $target ); |
| 22 |
} |
| 23 |
|
| 24 |
if ( $flags->is_ignore_trailing() ) { |
| 25 |
// Ignore trailing slashes |
| 26 |
$source = rtrim( $source, '/' ); |
| 27 |
$target = rtrim( $target, '/' ); |
| 28 |
} |
| 29 |
|
| 30 |
return $target === $source; |
| 31 |
} |
| 32 |
} |
| 33 |
|