1
0

ProviderSet.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Authentication\TwoFactorAuth;
  8. use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
  9. use OCP\Authentication\TwoFactorAuth\IProvider;
  10. use function array_filter;
  11. /**
  12. * Contains all two-factor provider information for the two-factor login challenge
  13. */
  14. class ProviderSet {
  15. /** @var IProvider */
  16. private $providers;
  17. /** @var bool */
  18. private $providerMissing;
  19. /**
  20. * @param IProvider[] $providers
  21. * @param bool $providerMissing
  22. */
  23. public function __construct(array $providers, bool $providerMissing) {
  24. $this->providers = [];
  25. foreach ($providers as $provider) {
  26. $this->providers[$provider->getId()] = $provider;
  27. }
  28. $this->providerMissing = $providerMissing;
  29. }
  30. /**
  31. * @param string $providerId
  32. * @return IProvider|null
  33. */
  34. public function getProvider(string $providerId) {
  35. return $this->providers[$providerId] ?? null;
  36. }
  37. /**
  38. * @return IProvider[]
  39. */
  40. public function getProviders(): array {
  41. return $this->providers;
  42. }
  43. /**
  44. * @return IProvider[]
  45. */
  46. public function getPrimaryProviders(): array {
  47. return array_filter($this->providers, function (IProvider $provider) {
  48. return !($provider instanceof BackupCodesProvider);
  49. });
  50. }
  51. public function isProviderMissing(): bool {
  52. return $this->providerMissing;
  53. }
  54. }