Automattic\WooCommerce\Internal\Utilities

URL::get_url()publicWC 1.0

Outputs the processed URL.

Borrows from https://www.php.net/manual/en/function.parse-url.php#106731

Method of the class: URL{}

No Hooks.

Return

String.

Usage

$URL = new URL();
$URL->get_url( $component_overrides ): string;
$component_overrides(array)
If provided, these will override values set in $this->components.
Default: array()

URL::get_url() code WC 9.3.3

public function get_url( array $component_overrides = array() ): string {
	$components = array_merge( $this->components, $component_overrides );

	$scheme = null !== $components['scheme'] ? $components['scheme'] . '://' : '//';
	$host   = null !== $components['host'] ? $components['host'] : '';
	$port   = null !== $components['port'] ? ':' . $components['port'] : '';
	$path   = $this->get_path( $components['path'] );

	// Special handling for hostless URLs (typically, filepaths) referencing the current working directory.
	if ( '' === $host && ( '' === $path || '.' === $path ) ) {
		$path = './';
	}

	$user      = null !== $components['user'] ? $components['user'] : '';
	$pass      = null !== $components['pass'] ? ':' . $components['pass'] : '';
	$user_pass = ( ! empty( $user ) || ! empty( $pass ) ) ? $user . $pass . '@' : '';

	$query    = null !== $components['query'] ? '?' . $components['query'] : '';
	$fragment = null !== $components['fragment'] ? '#' . $components['fragment'] : '';

	return $scheme . $user_pass . $host . $port . $path . $query . $fragment;
}