You've already forked dolibarr-api
134 lines
3.5 KiB
PHP
134 lines
3.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Magdev\DolibarrApi\Model;
|
||
|
|
|
||
|
|
use DateTimeImmutable;
|
||
|
|
use DateTimeZone;
|
||
|
|
|
||
|
|
class StatusModel extends AbstractModel implements ModelInterface
|
||
|
|
{
|
||
|
|
private ?string $dolibarVersion = null;
|
||
|
|
private ?bool $accessLocked = null;
|
||
|
|
private ?string $environment = null;
|
||
|
|
private ?DateTimeImmutable $timestampNowUtc = null;
|
||
|
|
private ?DateTimeZone $timestampPhpTz = null;
|
||
|
|
private ?DateTimeImmutable $dateTz = null;
|
||
|
|
|
||
|
|
public function __construct(?array $data = null)
|
||
|
|
{
|
||
|
|
if (is_array($data)) {
|
||
|
|
$this->fromArray(data: $data);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function fromArray(array $data): static
|
||
|
|
{
|
||
|
|
$this->setDolibarrVersion(dolibarVersion: $data['dolibarr_version'])
|
||
|
|
->setAccessLocked(accessLocked: (bool) $data['access_locked'])
|
||
|
|
->setEnvironment(environment: $data['environment'])
|
||
|
|
->setTimestampNowUtc(timestampNowUtc: new DateTimeImmutable('@'.$data['timestamp_now_utc'], new DateTimeZone('UTC')))
|
||
|
|
->setDateTz(dateTz: $data['date_tz'])
|
||
|
|
->setTimestampPhpTz(timestampPhpTz: $data['timestamp_php_tz'])
|
||
|
|
->setStatusCode(statusCode: $data['code'])
|
||
|
|
;
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toArray(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'dolibarr_version' => $this->getDolibarrVersion(),
|
||
|
|
'access_locked' => (int) $this->isAccessLocked(),
|
||
|
|
'environment' => $this->getEnvironment(),
|
||
|
|
'timestamp_now_utc' => $this->getTimestampNowUtc(),
|
||
|
|
'timestamp_php_tz' => $this->getTimestampPhpTz(),
|
||
|
|
'date_tz' => $this->getDateTz(),
|
||
|
|
'code' => $this->getStatusCode(),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getDolibarrVersion(): ?string
|
||
|
|
{
|
||
|
|
return $this->dolibarVersion;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setDolibarrVersion(?string $dolibarVersion): self
|
||
|
|
{
|
||
|
|
$this->dolibarVersion = $dolibarVersion;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isAccessLocked(): ?bool
|
||
|
|
{
|
||
|
|
return $this->accessLocked;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setAccessLocked(?bool $accessLocked): self
|
||
|
|
{
|
||
|
|
$this->accessLocked = $accessLocked;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getEnvironment(): ?string
|
||
|
|
{
|
||
|
|
return $this->environment;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setEnvironment(?string $environment): self
|
||
|
|
{
|
||
|
|
$this->environment = $environment;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getTimestampNowUtc(): ?DateTimeImmutable
|
||
|
|
{
|
||
|
|
return $this->timestampNowUtc;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setTimestampNowUtc(DateTimeImmutable|string|null $timestampNowUtc): self
|
||
|
|
{
|
||
|
|
if (is_string($timestampNowUtc)) {
|
||
|
|
$timestampNowUtc = new DateTimeImmutable($timestampNowUtc, new DateTimeZone('UTC'));
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->timestampNowUtc = $timestampNowUtc;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getTimestampPhpTz(): ?DateTimeZone
|
||
|
|
{
|
||
|
|
return $this->timestampPhpTz;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setTimestampPhpTz(DateTimeZone|string|null $timestampPhpTz): self
|
||
|
|
{
|
||
|
|
if (is_string($timestampPhpTz)) {
|
||
|
|
$timestampPhpTz = new DateTimeZone($timestampPhpTz);
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->timestampPhpTz = $timestampPhpTz;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getDateTz(): ?DateTimeImmutable
|
||
|
|
{
|
||
|
|
return $this->dateTz;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setDateTz(DateTimeImmutable|string|null $dateTz): self
|
||
|
|
{
|
||
|
|
if (is_string($dateTz)) {
|
||
|
|
$dateTz = new DateTimeImmutable($dateTz);
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->dateTz = $dateTz;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
}
|