Action.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace OC\Notification;
  9. use OCP\Notification\IAction;
  10. use OCP\Notification\InvalidValueException;
  11. class Action implements IAction {
  12. protected string $label = '';
  13. protected string $labelParsed = '';
  14. protected string $link = '';
  15. protected string $requestType = '';
  16. protected bool $primary = false;
  17. /**
  18. * {@inheritDoc}
  19. */
  20. public function setLabel(string $label): IAction {
  21. if ($label === '' || isset($label[32])) {
  22. throw new InvalidValueException('label');
  23. }
  24. $this->label = $label;
  25. return $this;
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function getLabel(): string {
  31. return $this->label;
  32. }
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public function setParsedLabel(string $label): IAction {
  37. if ($label === '') {
  38. throw new InvalidValueException('parsedLabel');
  39. }
  40. $this->labelParsed = $label;
  41. return $this;
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public function getParsedLabel(): string {
  47. return $this->labelParsed;
  48. }
  49. /**
  50. * {@inheritDoc}
  51. */
  52. public function setPrimary(bool $primary): IAction {
  53. $this->primary = $primary;
  54. return $this;
  55. }
  56. /**
  57. * {@inheritDoc}
  58. */
  59. public function isPrimary(): bool {
  60. return $this->primary;
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. public function setLink(string $link, string $requestType): IAction {
  66. if ($link === '' || isset($link[256])) {
  67. throw new InvalidValueException('link');
  68. }
  69. if (!in_array($requestType, [
  70. self::TYPE_GET,
  71. self::TYPE_POST,
  72. self::TYPE_PUT,
  73. self::TYPE_DELETE,
  74. self::TYPE_WEB,
  75. ], true)) {
  76. throw new InvalidValueException('requestType');
  77. }
  78. $this->link = $link;
  79. $this->requestType = $requestType;
  80. return $this;
  81. }
  82. /**
  83. * {@inheritDoc}
  84. */
  85. public function getLink(): string {
  86. return $this->link;
  87. }
  88. /**
  89. * {@inheritDoc}
  90. */
  91. public function getRequestType(): string {
  92. return $this->requestType;
  93. }
  94. /**
  95. * {@inheritDoc}
  96. */
  97. public function isValid(): bool {
  98. return $this->label !== '' && $this->link !== '';
  99. }
  100. /**
  101. * {@inheritDoc}
  102. */
  103. public function isValidParsed(): bool {
  104. return $this->labelParsed !== '' && $this->link !== '';
  105. }
  106. }