You've already forked listmonk-api
96 lines
2.0 KiB
PHP
96 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Magdev\ListmonkApi\Model\Traits;
|
||
|
|
|
||
|
|
trait DefaultPropertiesTrait
|
||
|
|
{
|
||
|
|
protected ?int $id = null;
|
||
|
|
protected ?string $uuid = null;
|
||
|
|
protected ?\DateTimeInterface $createdAt = null;
|
||
|
|
protected ?\DateTimeInterface $updatedAt = null;
|
||
|
|
|
||
|
|
public function getId(): ?int
|
||
|
|
{
|
||
|
|
return $this->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setId(?int $id): self
|
||
|
|
{
|
||
|
|
$this->id = $id;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getUuid(): ?string
|
||
|
|
{
|
||
|
|
return $this->uuid;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setUuid(?string $uuid): self
|
||
|
|
{
|
||
|
|
$this->uuid = $uuid;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getCreatedAt(): ?\DateTimeInterface
|
||
|
|
{
|
||
|
|
return $this->createdAt;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setCreatedAt(\DateTimeInterface|string|null $createdAt): self
|
||
|
|
{
|
||
|
|
if (is_string($createdAt)) {
|
||
|
|
$createdAt = new \DateTime($createdAt);
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->createdAt = $createdAt;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getUpdatedAt(): ?\DateTimeInterface
|
||
|
|
{
|
||
|
|
return $this->updatedAt;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setUpdatedAt(\DateTimeInterface|string|null $updatedAt): self
|
||
|
|
{
|
||
|
|
if (is_string($updatedAt)) {
|
||
|
|
$updatedAt = new \DateTime($updatedAt);
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->updatedAt = $updatedAt;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function fromArray(array $data): static
|
||
|
|
{
|
||
|
|
if (isset($data['id'])) {
|
||
|
|
$this->setId($data['id']);
|
||
|
|
}
|
||
|
|
if (isset($data['uuid'])) {
|
||
|
|
$this->setUuid($data['uuid']);
|
||
|
|
}
|
||
|
|
if (isset($data['created_at'])) {
|
||
|
|
$this->setCreatedAt($data['created_at']);
|
||
|
|
}
|
||
|
|
if (isset($data['updated_at'])) {
|
||
|
|
$this->setUpdatedAt($data['updated_at']);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toArray(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'id' => $this->getId(),
|
||
|
|
'uuid' => $this->getUuid(),
|
||
|
|
'created_at' => $this->getCreatedAt(),
|
||
|
|
'updated_at' => $this->getUpdatedAt(),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|