TemplateFileCreator.php 3.2 KB

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