- Created a new template for the cart rule form with custom label, switch, and choice widgets. - Implemented the InPost Pay block in the order details template for displaying delivery method, APM, and VAT invoice request. - Added legacy support for the order details template to maintain compatibility with older PrestaShop versions.
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace izi\prestashop\Http\Util;
|
|
|
|
final class UriResolver
|
|
{
|
|
public static function resolve(string $uri, string $baseUri): string
|
|
{
|
|
$uriParts = parse_url($uri);
|
|
|
|
if (!empty($uriParts['host'])) {
|
|
return $uri;
|
|
}
|
|
|
|
$baseUriParts = parse_url($baseUri);
|
|
$uriParts['path'] = self::resolvePath($baseUriParts, $uriParts);
|
|
$uriParts += $baseUriParts;
|
|
|
|
return http_build_url($uriParts);
|
|
}
|
|
|
|
private static function resolvePath(array $baseUri, array $uri): string
|
|
{
|
|
$basePath = $baseUri['path'] ?? null;
|
|
$path = $uri['path'] ?? null;
|
|
|
|
if (null === $path) {
|
|
$path = $basePath;
|
|
} elseif ('/' !== $path[0]) {
|
|
if (null === $basePath) {
|
|
$path = '/' . $path;
|
|
} else {
|
|
$segments = explode('/', $basePath);
|
|
array_splice($segments, -1, 1, [$path]);
|
|
$path = implode('/', $segments);
|
|
}
|
|
}
|
|
|
|
return empty($path) ? '/' : $path;
|
|
}
|
|
}
|