TemplateFileCreator.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 ?float $ratio */
  38. protected $ratio = null;
  39. protected $order = 100;
  40. /**
  41. * @since 27.0.0
  42. * @deprecated 28.0.0
  43. */
  44. protected string $actionLabel = '';
  45. /**
  46. * @since 21.0.0
  47. */
  48. public function __construct(
  49. string $appId, string $actionName, string $fileExtension
  50. ) {
  51. $this->appId = $appId;
  52. $this->actionName = $actionName;
  53. $this->fileExtension = $fileExtension;
  54. }
  55. /**
  56. * @since 21.0.0
  57. */
  58. public function getAppId(): string {
  59. return $this->appId;
  60. }
  61. /**
  62. * @since 21.0.0
  63. */
  64. public function setIconClass(string $iconClass): TemplateFileCreator {
  65. $this->iconClass = $iconClass;
  66. return $this;
  67. }
  68. /**
  69. * @since 21.0.0
  70. */
  71. public function addMimetype(string $mimetype): TemplateFileCreator {
  72. $this->mimetypes[] = $mimetype;
  73. return $this;
  74. }
  75. /**
  76. * @since 21.0.0
  77. */
  78. public function getMimetypes(): array {
  79. return $this->mimetypes;
  80. }
  81. /**
  82. * @since 21.0.0
  83. */
  84. public function setRatio(float $ratio): TemplateFileCreator {
  85. $this->ratio = $ratio;
  86. return $this;
  87. }
  88. /**
  89. * @param int $order order in which the create action shall be listed
  90. * @since 21.0.0
  91. */
  92. public function setOrder(int $order): TemplateFileCreator {
  93. $this->order = $order;
  94. return $this;
  95. }
  96. /**
  97. * @since 21.0.0
  98. */
  99. public function getOrder(): int {
  100. return $this->order;
  101. }
  102. /**
  103. * @since 27.0.0
  104. */
  105. public function setActionLabel(string $actionLabel): TemplateFileCreator {
  106. $this->actionLabel = $actionLabel;
  107. return $this;
  108. }
  109. /**
  110. * @since 27.0.0
  111. */
  112. public function getActionLabel(): string {
  113. return $this->actionLabel;
  114. }
  115. /**
  116. * @since 21.0.0
  117. * @return array{app: string, label: string, extension: string, iconClass: ?string, mimetypes: string[], ratio: ?float, actionLabel: string}
  118. */
  119. public function jsonSerialize(): array {
  120. return [
  121. 'app' => $this->appId,
  122. 'label' => $this->actionName,
  123. 'extension' => $this->fileExtension,
  124. 'iconClass' => $this->iconClass,
  125. 'mimetypes' => $this->mimetypes,
  126. 'ratio' => $this->ratio,
  127. 'actionLabel' => $this->actionLabel,
  128. ];
  129. }
  130. }