src/Entity/RegistryEntry.php line 46
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\Get,
ApiPlatform\Metadata\GetCollection,
ApiPlatform\Metadata\ApiFilter,
ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\TimestampableTrait,
App\Repository\RegistryEntryRepository;
use Ramsey\Uuid\UuidInterface,
Ramsey\Uuid\Uuid;
#[ApiResource(
description: 'Registry entries',
normalizationContext: ['groups' => ['read', 'read:' . self::class]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . self::class . '")',
order: ['createdAt' => 'desc'],
operations: [
new GetCollection(),
new Get()
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(SearchFilter::class, properties: [
'username' => 'partial',
'operationName' => 'partial',
'resourceUuid' => 'exact',
'requestMethod' => 'exact',
'ip' => 'partial'
])]
#[ApiFilter(OrderFilter::class, properties: ['username', 'ip', 'createdAt', 'updatedAt'])]
#[ORM\Entity(repositoryClass: RegistryEntryRepository::class)]
class RegistryEntry
{
use IdTrait,
UuidTrait,
TimestampableTrait;
#[ApiProperty(description: 'Admin')]
#[Groups(['read:' . self::class])]
#[ORM\ManyToOne(targetEntity: Admin::class, inversedBy: 'registryEntries')]
#[ORM\JoinColumn(onDelete: 'set null')]
private Admin $admin;
#[ApiProperty(description: 'Username')]
#[Groups(['read:' . self::class])]
#[ORM\Column(type: Types::STRING, length: 191)]
private string $username;
#[ApiProperty(description: 'Operation name')]
#[Groups(['read:' . self::class])]
#[ORM\Column(type: Types::STRING, length: 255)]
private string $operationName;
#[ApiProperty(description: 'Resource class')]
#[ORM\Column(type: Types::STRING, length: 255)]
private string $resourceClass;
#[ApiProperty(description: 'Input class')]
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $inputClass;
#[ApiProperty(description: 'Uuid of resource')]
#[Groups(['read:' . self::class])]
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $resourceUuid = null;
#[ApiProperty(description: 'Request method')]
#[Groups(['read:' . self::class])]
#[ORM\Column(type: Types::STRING, length: 127)]
private string $requestMethod;
#[ApiProperty(description: 'Request uri')]
#[Groups(['read:' . self::class])]
#[ORM\Column(type: Types::STRING)]
private string $requestUri;
#[ApiProperty(description: 'Origin ip')]
#[Groups(['read:' . self::class])]
#[ORM\Column(type: Types::STRING, length: 255)]
private string $ip;
public function __construct(
Admin $admin,
string $username,
string $operationName,
string $resourceClass,
mixed $inputData,
?string $resourceUuid,
string $requestMethod,
string $requestUri,
string $ip
) {
$this->setUuid();
$this->admin = $admin;
$this->username = $username;
$this->operationName = $operationName;
$this->resourceClass = $resourceClass;
$this->inputClass = $inputData && is_object($inputData) ? get_class($inputData) : null;
$this->resourceUuid = $resourceUuid;
$this->requestMethod = $requestMethod;
$this->requestUri = $requestUri;
$this->ip = $ip;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getAdmin(): ?Admin
{
return $this->admin;
}
public function getUsername(): string
{
return $this->username;
}
public function getOperationName(): string
{
return $this->operationName;
}
public function getResourceFullyQualifiedClass(): string
{
return $this->resourceClass;
}
#[Groups(['read'])]
public function getResourceClass(): string
{
return short_class_name($this->resourceClass);
}
public function getInputClass(): ?string
{
return $this->inputClass;
}
public function getResourceUuid(): UuidInterface|string|null
{
return $this->resourceUuid && Uuid::isValid($this->resourceUuid)
? Uuid::fromString($this->resourceUuid)
: $this->resourceUuid;
}
public function getRequestMethod(): string
{
return $this->requestMethod;
}
public function getRequestUri(): string
{
return $this->requestUri;
}
public function getIp(): string
{
return $this->ip;
}
}