20 private $errorCollection;
35 private static function getInstance() :
self
40 private function __construct()
45 private function setClientId($clientId) :
self
49 if(isset($clientId,$this->service,$this->type) && is_int($clientId))
51 $authAdapter = $this->service::getAuthAdapter($this->type);
54 $this->service->setClientId($clientId);
56 if($authAdapter->hasAuth())
58 $this->clientId = $clientId;
62 $this->errorCollection->setError(
new Main\
Error(
"client has no auth"));
66 private function setEngineCode(
$code) :
self
74 if($this->service instanceof
IInternalService && $this->service::canUseAsInternal())
76 $this->engineCode =
$code;
77 return $this->setType($this->service::getTypeByEngine($this->engineCode));
81 catch (\Throwable $exception)
83 $this->errorCollection->setError(
new Main\
Error($exception->getMessage()));
88 private function setType($type) :
self
92 if(isset($type) && in_array($type,$this->service::getTypes()) && in_array($type,
Service::getTypes()))
97 $this->errorCollection->setError(
new Main\
Error(
"service not support type"));
101 private function run() :
self
105 $result = Internals\ServiceQueueTable::add([
106 'CLIENT_ID' => $this->clientId,
107 'SERVICE_TYPE' => $this->engineCode,
108 'TYPE' => $this->type
110 $result->isSuccess()?:$this->errorCollection->add(
$result->getErrors());
114 private function clearCache()
123 private function sendEvent() :
self
132 if(
$result->getType() === EventResult::ERROR)
134 $this->errors()->add(
$errors =
$result->getParameters()[
'ERROR_COLLECTION'] ?? []);
142 return $this->errorCollection->count() > 0;
144 private function getEventStatus() :
int
146 return $this->
hasErrors() ? EventResult::ERROR : EventResult::SUCCESS;
150 return $this->errorCollection;
154 return new EventResult($this->getEventStatus(), [
'ERROR_COLLECTION' => $this->errors()]);
160 static::getInstance()
161 ->setEngineCode($engineCode)
162 ->setClientId($clientId)