TemplateFileCreator.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Files\Template;
  8. /**
  9. * @since 21.0.0
  10. */
  11. final class TemplateFileCreator implements \JsonSerializable {
  12. protected $appId;
  13. /** @var string[] $mimetypes */
  14. protected $mimetypes = [];
  15. protected $actionName;
  16. protected $fileExtension;
  17. /** @var ?string $iconClass */
  18. protected $iconClass;
  19. /** @var ?string $iconSvgInline */
  20. protected $iconSvgInline;
  21. /** @var ?float $ratio */
  22. protected $ratio = null;
  23. protected $order = 100;
  24. /**
  25. * @since 27.0.0
  26. * @deprecated 28.0.0
  27. */
  28. protected string $actionLabel = '';
  29. /**
  30. * @since 21.0.0
  31. */
  32. public function __construct(
  33. string $appId, string $actionName, string $fileExtension
  34. ) {
  35. $this->appId = $appId;
  36. $this->actionName = $actionName;
  37. $this->fileExtension = $fileExtension;
  38. }
  39. /**
  40. * @since 21.0.0
  41. */
  42. public function getAppId(): string {
  43. return $this->appId;
  44. }
  45. /**
  46. * @since 21.0.0
  47. * @deprecated 29.0.0
  48. */
  49. public function setIconClass(string $iconClass): TemplateFileCreator {
  50. $this->iconClass = $iconClass;
  51. return $this;
  52. }
  53. /**
  54. * @since 29.0.0
  55. */
  56. public function setIconSvgInline(string $iconSvgInline): TemplateFileCreator {
  57. $this->iconSvgInline = $iconSvgInline;
  58. return $this;
  59. }
  60. /**
  61. * @since 21.0.0
  62. */
  63. public function addMimetype(string $mimetype): TemplateFileCreator {
  64. $this->mimetypes[] = $mimetype;
  65. return $this;
  66. }
  67. /**
  68. * @since 21.0.0
  69. */
  70. public function getMimetypes(): array {
  71. return $this->mimetypes;
  72. }
  73. /**
  74. * @since 21.0.0
  75. */
  76. public function setRatio(float $ratio): TemplateFileCreator {
  77. $this->ratio = $ratio;
  78. return $this;
  79. }
  80. /**
  81. * @param int $order order in which the create action shall be listed
  82. * @since 21.0.0
  83. */
  84. public function setOrder(int $order): TemplateFileCreator {
  85. $this->order = $order;
  86. return $this;
  87. }
  88. /**
  89. * @since 21.0.0
  90. */
  91. public function getOrder(): int {
  92. return $this->order;
  93. }
  94. /**
  95. * @since 27.0.0
  96. */
  97. public function setActionLabel(string $actionLabel): TemplateFileCreator {
  98. $this->actionLabel = $actionLabel;
  99. return $this;
  100. }
  101. /**
  102. * @since 27.0.0
  103. */
  104. public function getActionLabel(): string {
  105. return $this->actionLabel;
  106. }
  107. /**
  108. * @since 21.0.0
  109. * @return array{app: string, label: string, extension: string, iconClass: ?string, iconSvgInline: ?string, mimetypes: string[], ratio: ?float, actionLabel: string}
  110. */
  111. public function jsonSerialize(): array {
  112. return [
  113. 'app' => $this->appId,
  114. 'label' => $this->actionName,
  115. 'extension' => $this->fileExtension,
  116. 'iconClass' => $this->iconClass,
  117. 'iconSvgInline' => $this->iconSvgInline,
  118. 'mimetypes' => $this->mimetypes,
  119. 'ratio' => $this->ratio,
  120. 'actionLabel' => $this->actionLabel,
  121. ];
  122. }
  123. }