setOperation($operation); $this->setTimestamp($timestamp); $this->setTimestampFormat($timestampFormat); } /** * @param $apiResult * * @return static */ public static function fromApiResult(object $apiResult): self { return new self( $apiResult->operation, (new DateTime('now', new DateTimeZone('UTC')))->setTimestamp($apiResult->timestamp), $apiResult->timestamp_format ); } /** * @param array $dbState * * @return static */ public static function fromDbState(array $dbState): self { return new self( $dbState['operation'], (new DateTime('now', new DateTimeZone('UTC')))->setTimestamp($dbState['timestamp']), $dbState['timestamp_format'] ); } /** * @return array */ public function toArray(): array { return [ 'operation' => $this->getOperation(), 'timestamp' => $this->getTimestamp()->getTimestamp(), 'timestamp_format' => $this->getTimestampFormat(), ]; } /** * @return stdClass */ public function toApiResult(): stdClass { $apiResult = new stdClass(); $apiResult->operation = $this->getOperation(); $apiResult->timestamp = $this->getTimestamp()->getTimestamp(); $apiResult->timestamp_format = $this->getTimestampFormat(); return $apiResult; } /** * @return string */ public function getOperation(): string { return $this->operation; } /** * @param string $operation */ public function setOperation(string $operation): void { $this->operation = $operation; } /** * @return DateTimeInterface */ public function getTimestamp(): DateTimeInterface { return $this->timestamp; } /** * @param DateTimeInterface $timestamp */ public function setTimestamp(DateTimeInterface $timestamp): void { $this->timestamp = $timestamp; } /** * @return string */ public function getTimestampFormat(): string { return $this->timestampFormat; } /** * @param string $timestampFormat */ public function setTimestampFormat(string $timestampFormat): void { $this->timestampFormat = $timestampFormat; } }