return $target;
} if (Uri::
isRelativePathReference($target)) { // As the target is already highly relative we return it as-is. It would be possible to resolve
// the target with `$target = self::resolve($base, $target);` and then try make it more relative
// by removing a duplicate query. But let's not do that automatically.
return $target;
} if ($target->
getAuthority() !== '' &&
$base->
getAuthority() !==
$target->
getAuthority()) { return $target->
withScheme(''
);
} // We must remove the path before removing the authority because if the path starts with two slashes, the URI
// would turn invalid. And we also cannot set a relative path before removing the authority, as that is also
// invalid.
$emptyPathUri =
$target->
withScheme(''
)->
withPath(''
)->
withUserInfo(''
)->
withPort(null
)->
withHost(''
);
if ($base->
getPath() !==
$target->
getPath()) { return $emptyPathUri->
withPath(self::
getRelativePath($base,
$target));
}