credentialMapper = $credentialMapper; } public function findOneByCredentialId(string $publicKeyCredentialId): ?PublicKeyCredentialSource { try { $entity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialId); return $entity->toPublicKeyCredentialSource(); } catch (IMapperException $e) { return null; } } /** * @return PublicKeyCredentialSource[] */ public function findAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity): array { $uid = $publicKeyCredentialUserEntity->getId(); $entities = $this->credentialMapper->findAllForUid($uid); return array_map(function (PublicKeyCredentialEntity $entity) { return $entity->toPublicKeyCredentialSource(); }, $entities); } public function saveAndReturnCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, ?string $name = null): PublicKeyCredentialEntity { $oldEntity = null; try { $oldEntity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialSource->getPublicKeyCredentialId()); } catch (IMapperException $e) { } $defaultName = false; if ($name === null) { $defaultName = true; $name = 'default'; } $entity = PublicKeyCredentialEntity::fromPublicKeyCrendentialSource($name, $publicKeyCredentialSource); if ($oldEntity) { $entity->setId($oldEntity->getId()); if ($defaultName) { $entity->setName($oldEntity->getName()); } } return $this->credentialMapper->insertOrUpdate($entity); } public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, ?string $name = null): void { $this->saveAndReturnCredentialSource($publicKeyCredentialSource, $name); } }