FormFlashInterface.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * @package Grav\Framework\Form
  4. *
  5. * @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Framework\Form\Interfaces;
  9. use Psr\Http\Message\UploadedFileInterface;
  10. /**
  11. * Interface FormFlashInterface
  12. * @package Grav\Framework\Form\Interfaces
  13. */
  14. interface FormFlashInterface extends \JsonSerializable
  15. {
  16. /**
  17. * @param array $config Available configuration keys: session_id, unique_id, form_name
  18. */
  19. public function __construct($config);
  20. /**
  21. * Get unique form flash id if set.
  22. *
  23. * @return string
  24. */
  25. public function getId(): string;
  26. /**
  27. * Get session Id associated to this form instance.
  28. *
  29. * @return string
  30. */
  31. public function getSessionId(): string;
  32. /**
  33. * Get unique identifier associated to this form instance.
  34. *
  35. * @return string
  36. */
  37. public function getUniqueId(): string;
  38. /**
  39. * Get form name associated to this form instance.
  40. *
  41. * @return string
  42. */
  43. public function getFormName(): string;
  44. /**
  45. * Get URL associated to this form instance.
  46. *
  47. * @return string
  48. */
  49. public function getUrl(): string;
  50. /**
  51. * Get username from the user who was associated to this form instance.
  52. *
  53. * @return string
  54. */
  55. public function getUsername(): string;
  56. /**
  57. * Get email from the user who was associated to this form instance.
  58. *
  59. * @return string
  60. */
  61. public function getUserEmail(): string;
  62. /**
  63. * Get creation timestamp for this form flash.
  64. *
  65. * @return int
  66. */
  67. public function getCreatedTimestamp(): int;
  68. /**
  69. * Get last updated timestamp for this form flash.
  70. *
  71. * @return int
  72. */
  73. public function getUpdatedTimestamp(): int;
  74. /**
  75. * Get raw form data.
  76. *
  77. * @return array|null
  78. */
  79. public function getData(): ?array;
  80. /**
  81. * Set raw form data.
  82. *
  83. * @param array|null $data
  84. * @return void
  85. */
  86. public function setData(?array $data): void;
  87. /**
  88. * Check if this form flash exists.
  89. *
  90. * @return bool
  91. */
  92. public function exists(): bool;
  93. /**
  94. * Save this form flash.
  95. *
  96. * @return $this
  97. */
  98. public function save();
  99. /**
  100. * Delete this form flash.
  101. *
  102. * @return $this
  103. */
  104. public function delete();
  105. /**
  106. * Get all files associated to a form field.
  107. *
  108. * @param string $field
  109. * @return array
  110. */
  111. public function getFilesByField(string $field): array;
  112. /**
  113. * Get all files grouped by the associated form fields.
  114. *
  115. * @param bool $includeOriginal
  116. * @return array
  117. */
  118. public function getFilesByFields($includeOriginal = false): array;
  119. /**
  120. * Add uploaded file to the form flash.
  121. *
  122. * @param UploadedFileInterface $upload
  123. * @param string|null $field
  124. * @param array|null $crop
  125. * @return string Return name of the file
  126. */
  127. public function addUploadedFile(UploadedFileInterface $upload, string $field = null, array $crop = null): string;
  128. /**
  129. * Add existing file to the form flash.
  130. *
  131. * @param string $filename
  132. * @param string $field
  133. * @param array|null $crop
  134. * @return bool
  135. */
  136. public function addFile(string $filename, string $field, array $crop = null): bool;
  137. /**
  138. * Remove any file from form flash.
  139. *
  140. * @param string $name
  141. * @param string|null $field
  142. * @return bool
  143. */
  144. public function removeFile(string $name, string $field = null): bool;
  145. /**
  146. * Clear form flash from all uploaded files.
  147. *
  148. * @return void
  149. */
  150. public function clearFiles();
  151. /**
  152. * @return array
  153. */
  154. public function jsonSerialize(): array;
  155. }