Provider.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\TwoFactorBackupCodes\Activity;
  8. use InvalidArgumentException;
  9. use OCP\Activity\IEvent;
  10. use OCP\Activity\IManager;
  11. use OCP\Activity\IProvider;
  12. use OCP\IURLGenerator;
  13. use OCP\L10N\IFactory as L10nFactory;
  14. class Provider implements IProvider {
  15. /** @var L10nFactory */
  16. private $l10n;
  17. /** @var IURLGenerator */
  18. private $urlGenerator;
  19. /** @var IManager */
  20. private $activityManager;
  21. /**
  22. * @param L10nFactory $l10n
  23. * @param IURLGenerator $urlGenerator
  24. * @param IManager $activityManager
  25. */
  26. public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) {
  27. $this->urlGenerator = $urlGenerator;
  28. $this->activityManager = $activityManager;
  29. $this->l10n = $l10n;
  30. }
  31. public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
  32. if ($event->getApp() !== 'twofactor_backupcodes') {
  33. throw new InvalidArgumentException();
  34. }
  35. $l = $this->l10n->get('twofactor_backupcodes', $language);
  36. switch ($event->getSubject()) {
  37. case 'codes_generated':
  38. $event->setParsedSubject($l->t('You created two-factor backup codes for your account'));
  39. if ($this->activityManager->getRequirePNG()) {
  40. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png')));
  41. } else {
  42. $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
  43. }
  44. break;
  45. default:
  46. throw new InvalidArgumentException();
  47. }
  48. return $event;
  49. }
  50. }