FormFlashInterface.php 3.5 KB

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