Automattic\WooCommerce\Blocks
DependencyDetection::normalize_url
Normalize a URL by removing query strings and hash fragments.
This helps match URLs in stack traces which don't include query strings.
Method of the class: DependencyDetection{}
No Hooks.
Returns
String. Normalized URL without query string or hash.
Usage
// private - for code of main (parent) class only $result = $this->normalize_url( $url ): string;
- $url(string) (required)
- URL to normalize.
DependencyDetection::normalize_url() DependencyDetection::normalize url code WC 10.7.0
private function normalize_url( string $url ): string {
$scheme = wp_parse_url( $url, PHP_URL_SCHEME );
$host = wp_parse_url( $url, PHP_URL_HOST );
$path = wp_parse_url( $url, PHP_URL_PATH );
if ( $scheme && $host && $path ) {
$port = wp_parse_url( $url, PHP_URL_PORT );
return $scheme . '://' . $host . ( $port ? ':' . $port : '' ) . $path;
}
return $url;
}