DeclarativeSettingsGetValueEvent.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Settings\Events;
  8. use Exception;
  9. use OCP\EventDispatcher\Event;
  10. use OCP\IUser;
  11. use OCP\Settings\IDeclarativeSettingsForm;
  12. /**
  13. * @psalm-import-type DeclarativeSettingsValueTypes from IDeclarativeSettingsForm
  14. *
  15. * @since 29.0.0
  16. */
  17. class DeclarativeSettingsGetValueEvent extends Event {
  18. /**
  19. * @var ?DeclarativeSettingsValueTypes
  20. */
  21. private mixed $value = null;
  22. /**
  23. * @since 29.0.0
  24. */
  25. public function __construct(
  26. private IUser $user,
  27. private string $app,
  28. private string $formId,
  29. private string $fieldId,
  30. ) {
  31. parent::__construct();
  32. }
  33. /**
  34. * @since 29.0.0
  35. */
  36. public function getUser(): IUser {
  37. return $this->user;
  38. }
  39. /**
  40. * @since 29.0.0
  41. */
  42. public function getApp(): string {
  43. return $this->app;
  44. }
  45. /**
  46. * @since 29.0.0
  47. */
  48. public function getFormId(): string {
  49. return $this->formId;
  50. }
  51. /**
  52. * @since 29.0.0
  53. */
  54. public function getFieldId(): string {
  55. return $this->fieldId;
  56. }
  57. /**
  58. * @since 29.0.0
  59. */
  60. public function setValue(mixed $value): void {
  61. $this->value = $value;
  62. }
  63. /**
  64. * @return DeclarativeSettingsValueTypes
  65. * @throws Exception
  66. *
  67. * @since 29.0.0
  68. */
  69. public function getValue(): mixed {
  70. if ($this->value === null) {
  71. throw new Exception('Value not set');
  72. }
  73. return $this->value;
  74. }
  75. }