src/Log/Entity/Request.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Log\Entity;
  3. use App\Security\Entity\User;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity()
  10.  * @ORM\Table(name="log_request")
  11.  */
  12. class Request
  13. {
  14.     const STATE_NEW 0;
  15.     const STATE_VERIFIED 1;
  16.     const STATE_RESOLVED 9;
  17.     /**
  18.      * @var int
  19.      * @ORM\Column(type="integer")
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      */
  23.     protected int $id;
  24.     /**
  25.      * @var ?User
  26.      * @ORM\ManyToOne(targetEntity="App\Security\Entity\User")
  27.      * @ORM\JoinColumn(nullable=true)
  28.      */
  29.     protected ?User $user;
  30.     /**
  31.      * @var DateTime
  32.      * @ORM\Column(type="datetime")
  33.      */
  34.     protected DateTime $startAt;
  35.     /**
  36.      * @var ?DateTime
  37.      * @ORM\Column(type="datetime", nullable=true)
  38.      */
  39.     protected ?DateTime $finishAt;
  40.     /**
  41.      * @var ?int
  42.      * @ORM\Column(type="integer", nullable=true)
  43.      */
  44.     protected ?int $duration;
  45.     /**
  46.      * @var string
  47.      * @ORM\Column(type="text")
  48.      */
  49.     protected string $url;
  50.     /**
  51.      * @var array
  52.      * @ORM\Column(type="array")
  53.      */
  54.     protected array $requestData;
  55.     /**
  56.      * @var ?array
  57.      * @ORM\Column(type="array", nullable=true)
  58.      */
  59.     protected ?array $responseData;
  60.     /**
  61.      * @var ?int
  62.      * @ORM\Column(type="integer", nullable=true)
  63.      */
  64.     protected ?int $statusCode;
  65.     /**
  66.      * @var string|null
  67.      * @ORM\Column(type="text", nullable=true)
  68.      */
  69.     protected ?string $exception;
  70.     /**
  71.      * @var bool
  72.      * @ORM\Column(type="boolean")
  73.      */
  74.     protected bool $complete;
  75.     /**
  76.      * @var int
  77.      * @ORM\Column(type="smallint")
  78.      */
  79.     protected int $state self::STATE_NEW;
  80.     /**
  81.      * @var string|null
  82.      * @ORM\Column(nullable=true)
  83.      */
  84.     protected ?string $ip;
  85.     /**
  86.      * @var Collection<Log>
  87.      * @ORM\OneToMany(targetEntity="App\Log\Entity\Log", mappedBy="request", fetch="EXTRA_LAZY")
  88.      */
  89.     protected Collection $logs;
  90.     public function __construct()
  91.     {
  92.         $this->logs = new ArrayCollection();
  93.         $this->complete false;
  94.         $this->startAt = new DateTime();
  95.     }
  96.     /**
  97.      * @return int
  98.      */
  99.     public function getId(): int
  100.     {
  101.         return $this->id;
  102.     }
  103.     /**
  104.      * @param int $id
  105.      * @return Request
  106.      */
  107.     public function setId(int $id): Request
  108.     {
  109.         $this->id $id;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return ?User
  114.      */
  115.     public function getUser(): ?User
  116.     {
  117.         return $this->user;
  118.     }
  119.     /**
  120.      * @param User $user
  121.      * @return Request
  122.      */
  123.     public function setUser(User $user): Request
  124.     {
  125.         $this->user $user;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return DateTime
  130.      */
  131.     public function getStartAt(): DateTime
  132.     {
  133.         return $this->startAt;
  134.     }
  135.     /**
  136.      * @param DateTime $startAt
  137.      * @return Request
  138.      */
  139.     public function setStartAt(DateTime $startAt): Request
  140.     {
  141.         $this->startAt $startAt;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return DateTime|null
  146.      */
  147.     public function getFinishAt(): ?DateTime
  148.     {
  149.         return $this->finishAt;
  150.     }
  151.     /**
  152.      * @param DateTime|null $finishAt
  153.      * @return Request
  154.      */
  155.     public function setFinishAt(?DateTime $finishAt null): Request
  156.     {
  157.         $this->finishAt $finishAt ?: new DateTime();
  158.         if ($this->startAt && $this->finishAt){
  159.             $this->setDuration($this->finishAt->getTimestamp() - $this->startAt->getTimestamp());
  160.         }
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return ?int
  165.      */
  166.     public function getDuration(): ?int
  167.     {
  168.         return $this->duration;
  169.     }
  170.     /**
  171.      * @param int $duration
  172.      * @return Request
  173.      */
  174.     public function setDuration(int $duration): Request
  175.     {
  176.         $this->duration $duration;
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return string
  181.      */
  182.     public function getUrl(): string
  183.     {
  184.         return $this->url;
  185.     }
  186.     /**
  187.      * @param string $url
  188.      * @return Request
  189.      */
  190.     public function setUrl(string $url): Request
  191.     {
  192.         $this->url $url;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return ?array
  197.      */
  198.     public function getRequestData(): ?array
  199.     {
  200.         return $this->requestData;
  201.     }
  202.     /**
  203.      * @param array $requestData
  204.      * @return Request
  205.      */
  206.     public function setRequestData(array $requestData): Request
  207.     {
  208.         $this->requestData $requestData;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return ?array
  213.      */
  214.     public function getResponseData(): ?array
  215.     {
  216.         return $this->responseData;
  217.     }
  218.     /**
  219.      * @param array $responseData
  220.      * @return Request
  221.      */
  222.     public function setResponseData(array $responseData): Request
  223.     {
  224.         $this->responseData $responseData;
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return ?int
  229.      */
  230.     public function getStatusCode(): ?int
  231.     {
  232.         return $this->statusCode;
  233.     }
  234.     /**
  235.      * @param int $statusCode
  236.      * @return Request
  237.      */
  238.     public function setStatusCode(int $statusCode): Request
  239.     {
  240.         $this->statusCode $statusCode;
  241.         return $this;
  242.     }
  243.     /**
  244.      * @return string|null
  245.      */
  246.     public function getException(): ?string
  247.     {
  248.         return $this->exception;
  249.     }
  250.     /**
  251.      * @param string|null $exception
  252.      * @return Request
  253.      */
  254.     public function setException(?string $exception): Request
  255.     {
  256.         $this->exception $exception;
  257.         return $this;
  258.     }
  259.     /**
  260.      * @return bool
  261.      */
  262.     public function isComplete(): bool
  263.     {
  264.         return $this->complete;
  265.     }
  266.     /**
  267.      * @param bool $complete
  268.      * @return Request
  269.      */
  270.     public function setComplete(bool $complete true): Request
  271.     {
  272.         $this->complete $complete;
  273.         return $this;
  274.     }
  275.     /**
  276.      * @return int
  277.      */
  278.     public function getState(): int
  279.     {
  280.         return $this->state;
  281.     }
  282.     /**
  283.      * @param int $state
  284.      * @return Request
  285.      */
  286.     public function setState(int $state): Request
  287.     {
  288.         $this->state $state;
  289.         return $this;
  290.     }
  291.     /**
  292.      * @return Collection
  293.      */
  294.     public function getLogs(): Collection
  295.     {
  296.         return $this->logs;
  297.     }
  298.     /**
  299.      * @param Collection $logs
  300.      * @return Request
  301.      */
  302.     public function setLogs(Collection $logs): Request
  303.     {
  304.         $this->logs $logs;
  305.         return $this;
  306.     }
  307.     /**
  308.      * @return string|null
  309.      */
  310.     public function getIp(): ?string
  311.     {
  312.         return $this->ip;
  313.     }
  314.     /**
  315.      * @param string|null $ip
  316.      * @return Request
  317.      */
  318.     public function setIp(?string $ip): Request
  319.     {
  320.         $this->ip $ip;
  321.         return $this;
  322.     }
  323. }