1
0

Action.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Notification;
  24. use OCP\Notification\IAction;
  25. class Action implements IAction {
  26. /** @var string */
  27. protected $label;
  28. /** @var string */
  29. protected $labelParsed;
  30. /** @var string */
  31. protected $link;
  32. /** @var string */
  33. protected $requestType;
  34. /** @var string */
  35. protected $icon;
  36. /** @var bool */
  37. protected $primary;
  38. public function __construct() {
  39. $this->label = '';
  40. $this->labelParsed = '';
  41. $this->link = '';
  42. $this->requestType = '';
  43. $this->primary = false;
  44. }
  45. /**
  46. * @param string $label
  47. * @return $this
  48. * @throws \InvalidArgumentException if the label is invalid
  49. * @since 8.2.0
  50. */
  51. public function setLabel(string $label): IAction {
  52. if ($label === '' || isset($label[32])) {
  53. throw new \InvalidArgumentException('The given label is invalid');
  54. }
  55. $this->label = $label;
  56. return $this;
  57. }
  58. /**
  59. * @return string
  60. * @since 8.2.0
  61. */
  62. public function getLabel(): string {
  63. return $this->label;
  64. }
  65. /**
  66. * @param string $label
  67. * @return $this
  68. * @throws \InvalidArgumentException if the label is invalid
  69. * @since 8.2.0
  70. */
  71. public function setParsedLabel(string $label): IAction {
  72. if ($label === '') {
  73. throw new \InvalidArgumentException('The given parsed label is invalid');
  74. }
  75. $this->labelParsed = $label;
  76. return $this;
  77. }
  78. /**
  79. * @return string
  80. * @since 8.2.0
  81. */
  82. public function getParsedLabel(): string {
  83. return $this->labelParsed;
  84. }
  85. /**
  86. * @param $primary bool
  87. * @return $this
  88. * @since 9.0.0
  89. */
  90. public function setPrimary(bool $primary): IAction {
  91. $this->primary = $primary;
  92. return $this;
  93. }
  94. /**
  95. * @return bool
  96. * @since 9.0.0
  97. */
  98. public function isPrimary(): bool {
  99. return $this->primary;
  100. }
  101. /**
  102. * @param string $link
  103. * @param string $requestType
  104. * @return $this
  105. * @throws \InvalidArgumentException if the link is invalid
  106. * @since 8.2.0
  107. */
  108. public function setLink(string $link, string $requestType): IAction {
  109. if ($link === '' || isset($link[256])) {
  110. throw new \InvalidArgumentException('The given link is invalid');
  111. }
  112. if (!in_array($requestType, [
  113. self::TYPE_GET,
  114. self::TYPE_POST,
  115. self::TYPE_PUT,
  116. self::TYPE_DELETE,
  117. self::TYPE_WEB,
  118. ], true)) {
  119. throw new \InvalidArgumentException('The given request type is invalid');
  120. }
  121. $this->link = $link;
  122. $this->requestType = $requestType;
  123. return $this;
  124. }
  125. /**
  126. * @return string
  127. * @since 8.2.0
  128. */
  129. public function getLink(): string {
  130. return $this->link;
  131. }
  132. /**
  133. * @return string
  134. * @since 8.2.0
  135. */
  136. public function getRequestType(): string {
  137. return $this->requestType;
  138. }
  139. /**
  140. * @return bool
  141. */
  142. public function isValid(): bool {
  143. return $this->label !== '' && $this->link !== '';
  144. }
  145. /**
  146. * @return bool
  147. */
  148. public function isValidParsed(): bool {
  149. return $this->labelParsed !== '' && $this->link !== '';
  150. }
  151. }