Simplify ApiKey entity by exposing key as a readonly prop

This commit is contained in:
Alejandro Celaya
2024-11-04 14:22:39 +01:00
parent b5010e4d8c
commit 79c5418ac2
9 changed files with 28 additions and 46 deletions

View File

@@ -8,7 +8,6 @@ use Cake\Chronos\Chronos;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use ReflectionObject;
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition;
@@ -51,12 +50,7 @@ class ApiKeyFixture extends AbstractFixture implements DependentFixtureInterface
private function buildApiKey(string $key, bool $enabled, Chronos|null $expiresAt = null): ApiKey
{
$apiKey = ApiKey::fromMeta(ApiKeyMeta::fromParams(expirationDate: $expiresAt));
$ref = new ReflectionObject($apiKey);
$keyProp = $ref->getProperty('key');
$keyProp->setAccessible(true);
$keyProp->setValue($apiKey, $key);
$apiKey = ApiKey::fromMeta(ApiKeyMeta::fromParams(key: $key, expirationDate: $expiresAt));
if (! $enabled) {
$apiKey->disable();
}