TemplateFileCreator.php 3.0 KB

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