39 lines
938 B
PHP
39 lines
938 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\BusProNet\Utility;
|
|
|
|
class BookingUrlUtility
|
|
{
|
|
public function __construct(
|
|
private readonly string $defaultBaseUrl,
|
|
) {
|
|
}
|
|
|
|
public function build(int $hotelId, int $dateId, ?string $myEpUrl = null): string
|
|
{
|
|
$query = http_build_query([
|
|
'date_id' => $dateId,
|
|
'hotel_id' => $hotelId,
|
|
], '', '&', PHP_QUERY_RFC3986);
|
|
|
|
$baseUrlInput = null !== $myEpUrl && '' !== trim($myEpUrl)
|
|
? $myEpUrl
|
|
: $this->defaultBaseUrl;
|
|
$baseUrl = $this->normalizeBaseUrl($baseUrlInput);
|
|
if ('' === $baseUrl) {
|
|
return sprintf('/bookings/create?%s', $query);
|
|
}
|
|
|
|
return sprintf('%s/bookings/create?%s', $baseUrl, $query);
|
|
}
|
|
|
|
private function normalizeBaseUrl(string $url): string
|
|
{
|
|
$trimmedUrl = trim($url);
|
|
|
|
return rtrim($trimmedUrl, '/');
|
|
}
|
|
}
|