<?php
namespace App\EventListener\Client\Order;
use App\Entity\Client\Order\Order;
use App\Entity\Client\Store\StoreHeader;
use App\EventListener\GenericEvent;
use App\Service\AppManager;
use App\Service\Client\Order\OrderManager;
class OrderListener
{
private OrderManager $orderManager;
private AppManager $appManager;
public function __construct(OrderManager $orderManager, AppManager $appManager)
{
$this->orderManager = $orderManager;
$this->appManager = $appManager;
}
public function confirm(GenericEvent $genericEvent)
{
$order = $genericEvent->getSubject();
if (!$order instanceof Order) {
return;
}
if ($order->getHeader() instanceof StoreHeader) {
throw new \Exception('Order is locked.');
}
$this->orderManager->confirm($order);
$this->appManager->eventPersist($order->getHeader());
}
}