shlink/module/Rest/config/entities-mappings/Shlinkio.Shlink.Rest.Entity.ApiKey.php

52 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2019-10-05 10:26:10 -05:00
declare(strict_types=1);
namespace Shlinkio\Shlink\Rest;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
use Doctrine\ORM\Mapping\ClassMetadata;
2019-08-11 06:44:42 -05:00
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
use Shlinkio\Shlink\Rest\Entity\ApiKeyRole;
use function Shlinkio\Shlink\Core\determineTableName;
return static function (ClassMetadata $metadata, array $emConfig): void {
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable(determineTableName('api_keys', $emConfig))
->setCustomRepositoryClass(ApiKey\Repository\ApiKeyRepository::class);
$builder->createField('id', Types::BIGINT)
->makePrimaryKey()
->generatedValue('IDENTITY')
->option('unsigned', true)
->build();
$builder->createField('key', Types::STRING)
->columnName('`key`')
->unique()
->build();
2021-03-06 11:27:34 -06:00
$builder->createField('name', Types::STRING)
->columnName('`name`')
->nullable()
->build();
$builder->createField('expirationDate', ChronosDateTimeType::CHRONOS_DATETIME)
->columnName('expiration_date')
->nullable()
->build();
$builder->createField('enabled', Types::BOOLEAN)
->build();
$builder->createOneToMany('roles', ApiKeyRole::class)
->mappedBy('apiKey')
->setIndexBy('role')
->cascadePersist()
->orphanRemoval()
->build();
};