TemplateFileCreator.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net>
  5. *
  6. * @author John Molakvoæ <skjnldsv@protonmail.com>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCP\Files\Template;
  26. /**
  27. * @since 21.0.0
  28. */
  29. final class TemplateFileCreator implements \JsonSerializable {
  30. protected $appId;
  31. /** @var string[] $mimetypes */
  32. protected $mimetypes = [];
  33. protected $actionName;
  34. protected $fileExtension;
  35. /** @var ?string $iconClass */
  36. protected $iconClass;
  37. /** @var ?string $iconSvgInline */
  38. protected $iconSvgInline;
  39. /** @var ?float $ratio */
  40. protected $ratio = null;
  41. protected $order = 100;
  42. /**
  43. * @since 27.0.0
  44. * @deprecated 28.0.0
  45. */
  46. protected string $actionLabel = '';
  47. /**
  48. * @since 21.0.0
  49. */
  50. public function __construct(
  51. string $appId, string $actionName, string $fileExtension
  52. ) {
  53. $this->appId = $appId;
  54. $this->actionName = $actionName;
  55. $this->fileExtension = $fileExtension;
  56. }
  57. /**
  58. * @since 21.0.0
  59. */
  60. public function getAppId(): string {
  61. return $this->appId;
  62. }
  63. /**
  64. * @since 21.0.0
  65. * @deprecated 29.0.0
  66. */
  67. public function setIconClass(string $iconClass): TemplateFileCreator {
  68. $this->iconClass = $iconClass;
  69. return $this;
  70. }
  71. /**
  72. * @since 29.0.0
  73. */
  74. public function setIconSvgInline(string $iconSvgInline): TemplateFileCreator {
  75. $this->iconSvgInline = $iconSvgInline;
  76. return $this;
  77. }
  78. /**
  79. * @since 21.0.0
  80. */
  81. public function addMimetype(string $mimetype): TemplateFileCreator {
  82. $this->mimetypes[] = $mimetype;
  83. return $this;
  84. }
  85. /**
  86. * @since 21.0.0
  87. */
  88. public function getMimetypes(): array {
  89. return $this->mimetypes;
  90. }
  91. /**
  92. * @since 21.0.0
  93. */
  94. public function setRatio(float $ratio): TemplateFileCreator {
  95. $this->ratio = $ratio;
  96. return $this;
  97. }
  98. /**
  99. * @param int $order order in which the create action shall be listed
  100. * @since 21.0.0
  101. */
  102. public function setOrder(int $order): TemplateFileCreator {
  103. $this->order = $order;
  104. return $this;
  105. }
  106. /**
  107. * @since 21.0.0
  108. */
  109. public function getOrder(): int {
  110. return $this->order;
  111. }
  112. /**
  113. * @since 27.0.0
  114. */
  115. public function setActionLabel(string $actionLabel): TemplateFileCreator {
  116. $this->actionLabel = $actionLabel;
  117. return $this;
  118. }
  119. /**
  120. * @since 27.0.0
  121. */
  122. public function getActionLabel(): string {
  123. return $this->actionLabel;
  124. }
  125. /**
  126. * @since 21.0.0
  127. * @return array{app: string, label: string, extension: string, iconClass: ?string, iconSvgInline: ?string, mimetypes: string[], ratio: ?float, actionLabel: string}
  128. */
  129. public function jsonSerialize(): array {
  130. return [
  131. 'app' => $this->appId,
  132. 'label' => $this->actionName,
  133. 'extension' => $this->fileExtension,
  134. 'iconClass' => $this->iconClass,
  135. 'iconSvgInline' => $this->iconSvgInline,
  136. 'mimetypes' => $this->mimetypes,
  137. 'ratio' => $this->ratio,
  138. 'actionLabel' => $this->actionLabel,
  139. ];
  140. }
  141. }