Action.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. use OCP\Notification\InvalidValueException;
  26. class Action implements IAction {
  27. protected string $label = '';
  28. protected string $labelParsed = '';
  29. protected string $link = '';
  30. protected string $requestType = '';
  31. protected bool $primary = false;
  32. /**
  33. * {@inheritDoc}
  34. */
  35. public function setLabel(string $label): IAction {
  36. if ($label === '' || isset($label[32])) {
  37. throw new InvalidValueException('label');
  38. }
  39. $this->label = $label;
  40. return $this;
  41. }
  42. /**
  43. * {@inheritDoc}
  44. */
  45. public function getLabel(): string {
  46. return $this->label;
  47. }
  48. /**
  49. * {@inheritDoc}
  50. */
  51. public function setParsedLabel(string $label): IAction {
  52. if ($label === '') {
  53. throw new InvalidValueException('parsedLabel');
  54. }
  55. $this->labelParsed = $label;
  56. return $this;
  57. }
  58. /**
  59. * {@inheritDoc}
  60. */
  61. public function getParsedLabel(): string {
  62. return $this->labelParsed;
  63. }
  64. /**
  65. * {@inheritDoc}
  66. */
  67. public function setPrimary(bool $primary): IAction {
  68. $this->primary = $primary;
  69. return $this;
  70. }
  71. /**
  72. * {@inheritDoc}
  73. */
  74. public function isPrimary(): bool {
  75. return $this->primary;
  76. }
  77. /**
  78. * {@inheritDoc}
  79. */
  80. public function setLink(string $link, string $requestType): IAction {
  81. if ($link === '' || isset($link[256])) {
  82. throw new InvalidValueException('link');
  83. }
  84. if (!in_array($requestType, [
  85. self::TYPE_GET,
  86. self::TYPE_POST,
  87. self::TYPE_PUT,
  88. self::TYPE_DELETE,
  89. self::TYPE_WEB,
  90. ], true)) {
  91. throw new InvalidValueException('requestType');
  92. }
  93. $this->link = $link;
  94. $this->requestType = $requestType;
  95. return $this;
  96. }
  97. /**
  98. * {@inheritDoc}
  99. */
  100. public function getLink(): string {
  101. return $this->link;
  102. }
  103. /**
  104. * {@inheritDoc}
  105. */
  106. public function getRequestType(): string {
  107. return $this->requestType;
  108. }
  109. /**
  110. * {@inheritDoc}
  111. */
  112. public function isValid(): bool {
  113. return $this->label !== '' && $this->link !== '';
  114. }
  115. /**
  116. * {@inheritDoc}
  117. */
  118. public function isValidParsed(): bool {
  119. return $this->labelParsed !== '' && $this->link !== '';
  120. }
  121. }