<?phpnamespace App\Log\Entity;use App\Security\Entity\User;use DateTime;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity() * @ORM\Table(name="log_request") */class Request{ const STATE_NEW = 0; const STATE_VERIFIED = 1; const STATE_RESOLVED = 9; /** * @var int * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected int $id; /** * @var ?User * @ORM\ManyToOne(targetEntity="App\Security\Entity\User") * @ORM\JoinColumn(nullable=true) */ protected ?User $user; /** * @var DateTime * @ORM\Column(type="datetime") */ protected DateTime $startAt; /** * @var ?DateTime * @ORM\Column(type="datetime", nullable=true) */ protected ?DateTime $finishAt; /** * @var ?int * @ORM\Column(type="integer", nullable=true) */ protected ?int $duration; /** * @var string * @ORM\Column(type="text") */ protected string $url; /** * @var array * @ORM\Column(type="array") */ protected array $requestData; /** * @var ?array * @ORM\Column(type="array", nullable=true) */ protected ?array $responseData; /** * @var ?int * @ORM\Column(type="integer", nullable=true) */ protected ?int $statusCode; /** * @var string|null * @ORM\Column(type="text", nullable=true) */ protected ?string $exception; /** * @var bool * @ORM\Column(type="boolean") */ protected bool $complete; /** * @var int * @ORM\Column(type="smallint") */ protected int $state = self::STATE_NEW; /** * @var string|null * @ORM\Column(nullable=true) */ protected ?string $ip; /** * @var Collection<Log> * @ORM\OneToMany(targetEntity="App\Log\Entity\Log", mappedBy="request", fetch="EXTRA_LAZY") */ protected Collection $logs; public function __construct() { $this->logs = new ArrayCollection(); $this->complete = false; $this->startAt = new DateTime(); } /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id * @return Request */ public function setId(int $id): Request { $this->id = $id; return $this; } /** * @return ?User */ public function getUser(): ?User { return $this->user; } /** * @param User $user * @return Request */ public function setUser(User $user): Request { $this->user = $user; return $this; } /** * @return DateTime */ public function getStartAt(): DateTime { return $this->startAt; } /** * @param DateTime $startAt * @return Request */ public function setStartAt(DateTime $startAt): Request { $this->startAt = $startAt; return $this; } /** * @return DateTime|null */ public function getFinishAt(): ?DateTime { return $this->finishAt; } /** * @param DateTime|null $finishAt * @return Request */ public function setFinishAt(?DateTime $finishAt = null): Request { $this->finishAt = $finishAt ?: new DateTime(); if ($this->startAt && $this->finishAt){ $this->setDuration($this->finishAt->getTimestamp() - $this->startAt->getTimestamp()); } return $this; } /** * @return ?int */ public function getDuration(): ?int { return $this->duration; } /** * @param int $duration * @return Request */ public function setDuration(int $duration): Request { $this->duration = $duration; return $this; } /** * @return string */ public function getUrl(): string { return $this->url; } /** * @param string $url * @return Request */ public function setUrl(string $url): Request { $this->url = $url; return $this; } /** * @return ?array */ public function getRequestData(): ?array { return $this->requestData; } /** * @param array $requestData * @return Request */ public function setRequestData(array $requestData): Request { $this->requestData = $requestData; return $this; } /** * @return ?array */ public function getResponseData(): ?array { return $this->responseData; } /** * @param array $responseData * @return Request */ public function setResponseData(array $responseData): Request { $this->responseData = $responseData; return $this; } /** * @return ?int */ public function getStatusCode(): ?int { return $this->statusCode; } /** * @param int $statusCode * @return Request */ public function setStatusCode(int $statusCode): Request { $this->statusCode = $statusCode; return $this; } /** * @return string|null */ public function getException(): ?string { return $this->exception; } /** * @param string|null $exception * @return Request */ public function setException(?string $exception): Request { $this->exception = $exception; return $this; } /** * @return bool */ public function isComplete(): bool { return $this->complete; } /** * @param bool $complete * @return Request */ public function setComplete(bool $complete = true): Request { $this->complete = $complete; return $this; } /** * @return int */ public function getState(): int { return $this->state; } /** * @param int $state * @return Request */ public function setState(int $state): Request { $this->state = $state; return $this; } /** * @return Collection */ public function getLogs(): Collection { return $this->logs; } /** * @param Collection $logs * @return Request */ public function setLogs(Collection $logs): Request { $this->logs = $logs; return $this; } /** * @return string|null */ public function getIp(): ?string { return $this->ip; } /** * @param string|null $ip * @return Request */ public function setIp(?string $ip): Request { $this->ip = $ip; return $this; }}