Action.php 3.6 KB

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