57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\Groups\Accommodation;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
|
|
/**
|
|
* Resolves the terms and conditions a booking is concluded under.
|
|
*
|
|
* Which legal entity operates an accommodation depends on the country it is located in,
|
|
* and each entity has its own AGB document. Countries without a dedicated entity — and
|
|
* any country whose document is not configured in this environment — fall back to the
|
|
* general E&P terms.
|
|
*/
|
|
class AccommodationTermsUrlProvider
|
|
{
|
|
/** @var array<string, string> country code → terms document URL */
|
|
private array $termsUrls;
|
|
|
|
/**
|
|
* @param array<string, string> $config
|
|
*/
|
|
public function __construct(
|
|
array $config,
|
|
private readonly string $termsAndConditionsUrl,
|
|
) {
|
|
$this->termsUrls = $this->resolveConfig($config);
|
|
}
|
|
|
|
public function forAccommodation(?Accommodation $accommodation): string
|
|
{
|
|
$country = $accommodation?->getCountry();
|
|
$url = null !== $country ? ($this->termsUrls[$country->value] ?? '') : '';
|
|
|
|
return '' !== $url ? $url : $this->termsAndConditionsUrl;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, string> $config
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
private function resolveConfig(array $config): array
|
|
{
|
|
$resolver = new OptionsResolver();
|
|
$resolver->setRequired(['AT', 'CH', 'IT']);
|
|
$resolver->setAllowedTypes('AT', 'string');
|
|
$resolver->setAllowedTypes('CH', 'string');
|
|
$resolver->setAllowedTypes('IT', 'string');
|
|
|
|
return $resolver->resolve($config);
|
|
}
|
|
}
|