<?php
namespace App\Entity;
use App\Repository\ActionLogRepository;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ActionLogRepository::class)
*
* @ORM\HasLifecycleCallbacks()
*/
class ActionLog
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="actionLogs")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
private User|null $user;
/**
* @ORM\Column(type="string", length=10)
*/
private string $method;
/**
* @ORM\Column(type="text", length=255)
*/
private string $action;
/**
* @ORM\Column(name="controller_action", type="string", length=255)
*/
private string $controllerAction;
/**
* @var array<mixed>
* @ORM\Column(type="json", nullable=true)
*/
private array|null $body = [];
/**
* @ORM\Column(name="created_at", type="datetime")
*/
private DateTime|null $createdAt = null;
/**
* @ORM\Column(name="updated_at", type="datetime")
*/
private DateTime|null $updatedAt = null;
public function __construct()
{
$this->incrementCreatedAt();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return User|null
*/
public function getUser(): ?User
{
return $this->user;
}
/**
* @param User|null $user
* @return $this
*/
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @param string $method
* @return $this
*/
public function setMethod(string $method): self
{
$this->method = $method;
return $this;
}
/**
* @return string
*/
public function getAction(): string
{
return $this->action;
}
/**
* @param string $action
* @return $this
*/
public function setAction(string $action): self
{
$this->action = $action;
return $this;
}
/**
* @return string
*/
public function getControllerAction(): string
{
return $this->controllerAction;
}
/**
* @param string $controllerAction
* @return $this
*/
public function setControllerAction(string $controllerAction): self
{
$this->controllerAction = $controllerAction;
return $this;
}
/**
* @return array<mixed>|null
*/
public function getBody(): ?array
{
return $this->body;
}
/**
* @param array<mixed>|null $body
* @return $this
*/
public function setBody(?array $body): self
{
$this->body = $body;
return $this;
}
/**
* @return DateTime
*/
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @param DateTime $createdAt
* @return $this
*/
public function setCreatedAt(DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return DateTime
*/
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
/**
* @param DateTime $updatedAt
* @return $this
*/
public function setUpdatedAt(DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @ORM\PrePersist
*/
public function incrementCreatedAt(): void
{
if ($this->createdAt === null) {
$this->createdAt = new DateTime();
}
$this->updatedAt = new DateTime();
}
/**
* @ORM\PreUpdate
*/
public function incrementUpdatedAt(): void
{
$this->updatedAt = new DateTime();
}
}