<?php
namespace App\EventSubscriber;
use App\Entity\Client;
use App\Entity\ClientUrl;
use App\Entity\Property;
use App\Entity\PropertyUrl;
use App\Util\ClientUtil;
use App\Util\OnlineCheckinUtil;
use App\Util\PMSConnectorUtil;
use App\Util\PropertyUtil;
use App\Util\SystemUtil;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class KernelSubscriber implements EventSubscriberInterface
{
/**
* @var SystemUtil
*/
private $systemUtil;
/**
* @var PropertyUtil
*/
private $propertyUtil;
/**
* @var ClientUtil
*/
private $clientUtil;
/**
* KernelSubscriber constructor.
* @param PropertyUtil $propertyUtil
*/
public function __construct(SystemUtil $systemUtil, PropertyUtil $propertyUtil, ClientUtil $clientUtil)
{
$this->propertyUtil = $propertyUtil;
$this->clientUtil = $clientUtil;
$this->systemUtil = $systemUtil;
}
public function onKernelRequest(RequestEvent $event)
{
$url = $event->getRequest()->headers->get('host');
if (strpos($event->getRequest()->server->get('REQUEST_URI'), '/api/') !== false) {
return;
}
$hotelIdentifier = $event->getRequest()->get('identifier', $this->systemUtil->getCurrentPropertyIdentifier());
$client = $this->clientUtil->getClientByUrl($url);
if (!$client instanceof Client) {
return;
}
$property = $client->getProperties()->first();
if (!empty($hotelIdentifier)) {
$property = $this->propertyUtil->getPropertyByIdentifier($hotelIdentifier);
}
if (!$property instanceof Property) {
return;
}
$this->systemUtil->setCurrentPropertyIdentifier($property->getIdentifier());
$this->systemUtil->initProperty($property);
}
public static function getSubscribedEvents()
{
return [
'kernel.request' => 'onKernelRequest',
];
}
}