@@ -35,61 +35,61 @@ |
||
| 35 | 35 | |
| 36 | 36 | class CredentialRepository implements PublicKeyCredentialSourceRepository { |
| 37 | 37 | |
| 38 | - /** @var PublicKeyCredentialMapper */ |
|
| 39 | - private $credentialMapper; |
|
| 40 | - |
|
| 41 | - public function __construct(PublicKeyCredentialMapper $credentialMapper) { |
|
| 42 | - $this->credentialMapper = $credentialMapper; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function findOneByCredentialId(string $publicKeyCredentialId): ?PublicKeyCredentialSource { |
|
| 46 | - try { |
|
| 47 | - $entity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialId); |
|
| 48 | - return $entity->toPublicKeyCredentialSource(); |
|
| 49 | - } catch (IMapperException $e) { |
|
| 50 | - return null; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @return PublicKeyCredentialSource[] |
|
| 56 | - */ |
|
| 57 | - public function findAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity): array { |
|
| 58 | - $uid = $publicKeyCredentialUserEntity->getId(); |
|
| 59 | - $entities = $this->credentialMapper->findAllForUid($uid); |
|
| 60 | - |
|
| 61 | - return array_map(function (PublicKeyCredentialEntity $entity) { |
|
| 62 | - return $entity->toPublicKeyCredentialSource(); |
|
| 63 | - }, $entities); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function saveAndReturnCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): PublicKeyCredentialEntity { |
|
| 67 | - $oldEntity = null; |
|
| 68 | - |
|
| 69 | - try { |
|
| 70 | - $oldEntity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialSource->getPublicKeyCredentialId()); |
|
| 71 | - } catch (IMapperException $e) { |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $defaultName = false; |
|
| 75 | - if ($name === null) { |
|
| 76 | - $defaultName = true; |
|
| 77 | - $name = 'default'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $entity = PublicKeyCredentialEntity::fromPublicKeyCrendentialSource($name, $publicKeyCredentialSource); |
|
| 81 | - |
|
| 82 | - if ($oldEntity) { |
|
| 83 | - $entity->setId($oldEntity->getId()); |
|
| 84 | - if ($defaultName) { |
|
| 85 | - $entity->setName($oldEntity->getName()); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return $this->credentialMapper->insertOrUpdate($entity); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): void { |
|
| 93 | - $this->saveAndReturnCredentialSource($publicKeyCredentialSource, $name); |
|
| 94 | - } |
|
| 38 | + /** @var PublicKeyCredentialMapper */ |
|
| 39 | + private $credentialMapper; |
|
| 40 | + |
|
| 41 | + public function __construct(PublicKeyCredentialMapper $credentialMapper) { |
|
| 42 | + $this->credentialMapper = $credentialMapper; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function findOneByCredentialId(string $publicKeyCredentialId): ?PublicKeyCredentialSource { |
|
| 46 | + try { |
|
| 47 | + $entity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialId); |
|
| 48 | + return $entity->toPublicKeyCredentialSource(); |
|
| 49 | + } catch (IMapperException $e) { |
|
| 50 | + return null; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @return PublicKeyCredentialSource[] |
|
| 56 | + */ |
|
| 57 | + public function findAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity): array { |
|
| 58 | + $uid = $publicKeyCredentialUserEntity->getId(); |
|
| 59 | + $entities = $this->credentialMapper->findAllForUid($uid); |
|
| 60 | + |
|
| 61 | + return array_map(function (PublicKeyCredentialEntity $entity) { |
|
| 62 | + return $entity->toPublicKeyCredentialSource(); |
|
| 63 | + }, $entities); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function saveAndReturnCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): PublicKeyCredentialEntity { |
|
| 67 | + $oldEntity = null; |
|
| 68 | + |
|
| 69 | + try { |
|
| 70 | + $oldEntity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialSource->getPublicKeyCredentialId()); |
|
| 71 | + } catch (IMapperException $e) { |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $defaultName = false; |
|
| 75 | + if ($name === null) { |
|
| 76 | + $defaultName = true; |
|
| 77 | + $name = 'default'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $entity = PublicKeyCredentialEntity::fromPublicKeyCrendentialSource($name, $publicKeyCredentialSource); |
|
| 81 | + |
|
| 82 | + if ($oldEntity) { |
|
| 83 | + $entity->setId($oldEntity->getId()); |
|
| 84 | + if ($defaultName) { |
|
| 85 | + $entity->setName($oldEntity->getName()); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return $this->credentialMapper->insertOrUpdate($entity); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): void { |
|
| 93 | + $this->saveAndReturnCredentialSource($publicKeyCredentialSource, $name); |
|
| 94 | + } |
|
| 95 | 95 | } |