2015-05-22 07:26:49 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2020-12-08 18:40:33 +00:00
|
|
|
/** @noinspection PhpMissingFieldTypeInspection */
|
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Entity;
|
2015-05-22 07:26:49 +00:00
|
|
|
|
2019-08-14 23:50:53 +00:00
|
|
|
use App\Annotations\AuditLog;
|
2020-11-30 09:59:33 +00:00
|
|
|
use App\Security\SplitToken;
|
2018-12-22 00:01:04 +00:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2019-09-04 18:00:51 +00:00
|
|
|
use JsonSerializable;
|
2018-12-22 00:01:04 +00:00
|
|
|
|
2015-05-22 07:26:49 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Table(name="api_keys")
|
2020-12-07 09:30:39 +00:00
|
|
|
* @ORM\Entity(readOnly=true)
|
2019-08-14 23:50:53 +00:00
|
|
|
*
|
|
|
|
* @AuditLog\Auditable
|
2015-05-22 07:26:49 +00:00
|
|
|
*/
|
2019-09-04 18:00:51 +00:00
|
|
|
class ApiKey implements JsonSerializable
|
2015-05-22 07:26:49 +00:00
|
|
|
{
|
2021-02-28 02:50:45 +00:00
|
|
|
use Traits\HasSplitTokenFields;
|
2018-04-06 21:29:27 +00:00
|
|
|
use Traits\TruncateStrings;
|
|
|
|
|
2017-08-17 18:28:48 +00:00
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="api_keys", fetch="EAGER")
|
2018-12-22 00:01:04 +00:00
|
|
|
* @ORM\JoinColumns({
|
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="uid", onDelete="CASCADE")
|
2018-02-06 11:09:05 +00:00
|
|
|
* })
|
|
|
|
* @var User
|
2017-08-17 18:28:48 +00:00
|
|
|
*/
|
2018-02-06 11:09:05 +00:00
|
|
|
protected $user;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-20 11:33:49 +00:00
|
|
|
* @ORM\Column(name="comment", type="string", length=255, nullable=true)
|
2018-02-06 11:09:05 +00:00
|
|
|
* @var string|null
|
2017-08-17 18:28:48 +00:00
|
|
|
*/
|
2018-02-06 11:09:05 +00:00
|
|
|
protected $comment;
|
2017-08-17 18:28:48 +00:00
|
|
|
|
2020-11-30 09:59:33 +00:00
|
|
|
public function __construct(User $user, SplitToken $token)
|
2018-02-06 11:09:05 +00:00
|
|
|
{
|
|
|
|
$this->user = $user;
|
2021-02-28 02:50:45 +00:00
|
|
|
$this->setFromToken($token);
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 09:59:33 +00:00
|
|
|
public function getUser(): User
|
2017-01-24 00:17:50 +00:00
|
|
|
{
|
2020-11-30 09:59:33 +00:00
|
|
|
return $this->user;
|
2017-01-24 00:17:50 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 11:09:05 +00:00
|
|
|
/**
|
2019-08-14 23:50:53 +00:00
|
|
|
* @AuditLog\AuditIdentifier
|
2018-02-06 11:09:05 +00:00
|
|
|
*/
|
|
|
|
public function getComment(): ?string
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
2018-02-06 11:09:05 +00:00
|
|
|
return $this->comment;
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
2015-05-22 07:26:49 +00:00
|
|
|
|
2018-02-06 11:09:05 +00:00
|
|
|
public function setComment(?string $comment): void
|
2017-08-17 18:28:48 +00:00
|
|
|
{
|
2020-03-29 07:16:41 +00:00
|
|
|
$this->comment = $this->truncateString($comment);
|
2017-08-17 18:28:48 +00:00
|
|
|
}
|
2019-01-04 17:32:11 +00:00
|
|
|
|
2020-10-14 22:19:31 +00:00
|
|
|
/**
|
|
|
|
* @return mixed[]
|
|
|
|
*/
|
|
|
|
public function jsonSerialize(): array
|
2019-01-04 17:32:11 +00:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
|
|
|
'comment' => $this->comment,
|
|
|
|
];
|
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|