<?php
 namespace App\ImportEmailBookings; abstract class ManagerAbstract { protected ?string $skipReason = null; protected \App\Utils\EmailBox\GeneralAbstract $emailBox; protected \App\ImportEmailBookings\EmailsStorage $emailStorage; protected string $account; public function __construct( \App\Utils\EmailBox\GeneralAbstract $emailBox, \App\ImportEmailBookings\EmailsStorage $emailStorage, string $account) { $this->emailBox = $emailBox; $this->emailStorage = $emailStorage; $this->account = $account; } public function searchNewBookingEmails( ?\Engine\DateTime $oldestEmailDate=null ) :array { $emails = $this->searchAllBookingEmails($oldestEmailDate); $return = []; foreach ($emails as $idEmail => $parserVersion) { if (!$this->emailStorage->getDetails($this->account, $idEmail, false)) { $return[$idEmail] = $parserVersion; } } return $return; } abstract protected function searchAllBookingEmails( ?\Engine\DateTime $oldestEmailDate=null ) :array; protected function filterEmailsListIds(string $searchString) :array { return $this->emailBox->search($searchString); } public function getEmail(string $idEmail, bool $markAsSeen) :\PhpImap\IncomingMail { return $this->emailBox->getMail($idEmail, $markAsSeen); } public function getImportedOrder(\PhpImap\IncomingMail $email, string $parserVersion) :?\App\ImportedOrder\Order { $parserClass = "\\" . getClassNamespace(get_called_class()) . "\\" . $parserVersion . "\\Parser"; $parserObj = new $parserClass( $email->textHtml ); $parserObj->parse(); $ioPopulateClass = "\\" . getClassNamespace(get_called_class()) . "\\" . $parserVersion . "\\PopulateImportedOrder"; $ioPopulateObj = new $ioPopulateClass($parserObj); $impOrder = new \App\ImportedOrder\Order(); $ioPopulateObj->execute($impOrder); $this->skipReason = $ioPopulateObj->getSkipReason(); if ($this->skipReason) { return null; } return $impOrder; } public function storeImportedEmail(string $idEmail, int $idImportedOrder) :void { $supplier = end( explode("\\", getClassNamespace( get_called_class() )) ); $this->emailStorage->insert($this->account, $idEmail, $supplier, $idImportedOrder); } public function getSkipReason() :?string { return $this->skipReason; } } 