src/EventSubscriber/Quote/RequestForQuoteFileTypeResourceSubscriber.php line 30
<?phpnamespace App\EventSubscriber\Quote;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\EventDispatcher\GenericEvent;use Webmozart\Assert\Assert;use Sylius\Component\Customer\Model\CustomerInterface;use App\Repository\Customer\CustomerRepository;use App\Entity\Channel\ChannelEcodaAccountInfo;use App\Repository\Channel\ChannelEcodaAccountInfoRepository;use App\Repository\Channel\ChannelEcodaAccountTypeRepository;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;use App\Manager\EcodaAccountManager;use App\Entity\Quote\RequestForQuoteFileType;use App\Entity\Quote\RequestForQuoteFileTypeBlank;use App\Entity\Quote\RequestForQuoteFileTypeExample;class RequestForQuoteFileTypeResourceSubscriber implements EventSubscriberInterface{private $request;public function __construct(RequestStack $request){$this->request = $request->getCurrentRequest();}public function onSyliusEntityPreCreate(GenericEvent $event){$entity = $event->getSubject();Assert::isInstanceOf($entity, RequestForQuoteFileType::class);$this->uplaodFiles($entity);}public function onSyliusEntityPreUpdate(GenericEvent $event){$entity = $event->getSubject();Assert::isInstanceOf($entity, RequestForQuoteFileType::class);$this->uplaodFiles($entity);}private function uplaodFiles($entity){$example = $this->request->files->get('request_for_quote_file_type')['example']['file'];$blank = $this->request->files->get('request_for_quote_file_type')['blank']['file'];if($example){$exampleFile = new RequestForQuoteFileTypeExample();$exampleFile->setFile($example);$exampleFile->setUpdatedAt(new \DateTime());$entity->setExample($exampleFile);}else{$entity->setExample(null);}if($blank){$blankFile = new RequestForQuoteFileTypeBlank();$blankFile->setFile($blank);$blankFile->setUpdatedAt(new \DateTime());$entity->setBlank($blankFile);}else{$entity->setBlank(null);}//dd($entity);}public static function getSubscribedEvents(){return ['app.request_for_quote_file_type.pre_create' => 'onSyliusEntityPreCreate','app.request_for_quote_file_type.pre_update' => 'onSyliusEntityPreUpdate',];}}