DeclarativeSettingsGetValueEvent.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Kate Döen <kate.doeen@nextcloud.com>
  5. *
  6. * @author Kate Döen <kate.doeen@nextcloud.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCP\Settings\Events;
  25. use Exception;
  26. use OCP\EventDispatcher\Event;
  27. use OCP\IUser;
  28. use OCP\Settings\IDeclarativeSettingsForm;
  29. /**
  30. * @psalm-import-type DeclarativeSettingsValueTypes from IDeclarativeSettingsForm
  31. *
  32. * @since 29.0.0
  33. */
  34. class DeclarativeSettingsGetValueEvent extends Event {
  35. /**
  36. * @var ?DeclarativeSettingsValueTypes
  37. */
  38. private mixed $value = null;
  39. /**
  40. * @since 29.0.0
  41. */
  42. public function __construct(
  43. private IUser $user,
  44. private string $app,
  45. private string $formId,
  46. private string $fieldId,
  47. ) {
  48. parent::__construct();
  49. }
  50. /**
  51. * @since 29.0.0
  52. */
  53. public function getUser(): IUser {
  54. return $this->user;
  55. }
  56. /**
  57. * @since 29.0.0
  58. */
  59. public function getApp(): string {
  60. return $this->app;
  61. }
  62. /**
  63. * @since 29.0.0
  64. */
  65. public function getFormId(): string {
  66. return $this->formId;
  67. }
  68. /**
  69. * @since 29.0.0
  70. */
  71. public function getFieldId(): string {
  72. return $this->fieldId;
  73. }
  74. /**
  75. * @since 29.0.0
  76. */
  77. public function setValue(mixed $value): void {
  78. $this->value = $value;
  79. }
  80. /**
  81. * @return DeclarativeSettingsValueTypes
  82. * @throws Exception
  83. *
  84. * @since 29.0.0
  85. */
  86. public function getValue(): mixed {
  87. if ($this->value === null) {
  88. throw new Exception('Value not set');
  89. }
  90. return $this->value;
  91. }
  92. }