<?php
namespace App\EventListener\Custom\VinoLevice;
use App\Entity\Central\Client\Client;
use App\Entity\Client\Store\StoreCentral;
use App\EventListener\GenericEvent;
use App\Model\ShellExec;
use App\Service\ShellExecManager;
use App\Utils\ClientUtils;
class PostListener
{
private ShellExecManager $shellExecManager;
public function __construct(ShellExecManager $shellExecManager)
{
$this->shellExecManager = $shellExecManager;
}
public function postStoreCentralCreate(GenericEvent $genericEvent)
{
/** @var StoreCentral $entity */
$entity = $genericEvent->getSubject();
if (!$entity instanceof StoreCentral) {
return;
}
$this->isClient($genericEvent->getAppManager()->getClient());
$shellExec = new ShellExec('vinolevice:export_store_central', '--id=' . $entity->getId() . ' --kernel=vinolevice');
$this->shellExecManager->runShellExec($shellExec, true);
}
private function isClient($client)
{
if (!$client instanceof Client || $client->getCode() !== ClientUtils::VINOLEVICE) {
throw new \Exception('Bad client');
}
}
}