MediaObjectInterface.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /**
  3. * @package Grav\Common\Media
  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\Common\Media\Interfaces;
  9. use ArrayAccess;
  10. use Grav\Common\Data\Data;
  11. /**
  12. * Class implements media object interface.
  13. *
  14. * @property string $type
  15. * @property string $filename
  16. * @property string $filepath
  17. */
  18. interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObjectInterface, ArrayAccess
  19. {
  20. /**
  21. * Create a copy of this media object
  22. *
  23. * @return static
  24. */
  25. public function copy();
  26. /**
  27. * Return just metadata from the Medium object
  28. *
  29. * @return Data
  30. */
  31. public function meta();
  32. /**
  33. * Set querystring to file modification timestamp (or value provided as a parameter).
  34. *
  35. * @param string|int|null $timestamp
  36. * @return $this
  37. */
  38. public function setTimestamp($timestamp = null);
  39. /**
  40. * Returns an array containing just the metadata
  41. *
  42. * @return array
  43. */
  44. public function metadata();
  45. /**
  46. * Add meta file for the medium.
  47. *
  48. * @param string $filepath
  49. */
  50. public function addMetaFile($filepath);
  51. /**
  52. * Add alternative Medium to this Medium.
  53. *
  54. * @param int|float $ratio
  55. * @param MediaObjectInterface $alternative
  56. */
  57. public function addAlternative($ratio, MediaObjectInterface $alternative);
  58. /**
  59. * Get list of image alternatives. Includes the current media image as well.
  60. *
  61. * @param bool $withDerived If true, include generated images as well. If false, only return existing files.
  62. * @return array
  63. */
  64. public function getAlternatives(bool $withDerived = true): array;
  65. /**
  66. * Return string representation of the object (html).
  67. *
  68. * @return string
  69. */
  70. public function __toString();
  71. /**
  72. * Get/set querystring for the file's url
  73. *
  74. * @param string|null $querystring
  75. * @param bool $withQuestionmark
  76. * @return string
  77. */
  78. public function querystring($querystring = null, $withQuestionmark = true);
  79. /**
  80. * Get the URL with full querystring
  81. *
  82. * @param string $url
  83. * @return string
  84. */
  85. public function urlQuerystring($url);
  86. /**
  87. * Get/set hash for the file's url
  88. *
  89. * @param string|null $hash
  90. * @param bool $withHash
  91. * @return string
  92. */
  93. public function urlHash($hash = null, $withHash = true);
  94. /**
  95. * Get an element (is array) that can be rendered by the Parsedown engine
  96. *
  97. * @param string|null $title
  98. * @param string|null $alt
  99. * @param string|null $class
  100. * @param string|null $id
  101. * @param bool $reset
  102. * @return array
  103. */
  104. public function parsedownElement($title = null, $alt = null, $class = null, $id = null, $reset = true);
  105. /**
  106. * Reset medium.
  107. *
  108. * @return $this
  109. */
  110. public function reset();
  111. /**
  112. * Add custom attribute to medium.
  113. *
  114. * @param string $attribute
  115. * @param string $value
  116. * @return $this
  117. */
  118. public function attribute($attribute = null, $value = '');
  119. /**
  120. * Switch display mode.
  121. *
  122. * @param string $mode
  123. * @return MediaObjectInterface|null
  124. */
  125. public function display($mode = 'source');
  126. /**
  127. * Helper method to determine if this media item has a thumbnail or not
  128. *
  129. * @param string $type;
  130. * @return bool
  131. */
  132. public function thumbnailExists($type = 'page');
  133. /**
  134. * Switch thumbnail.
  135. *
  136. * @param string $type
  137. * @return $this
  138. */
  139. public function thumbnail($type = 'auto');
  140. /**
  141. * Turn the current Medium into a Link
  142. *
  143. * @param bool $reset
  144. * @param array $attributes
  145. * @return MediaLinkInterface
  146. */
  147. public function link($reset = true, array $attributes = []);
  148. /**
  149. * Turn the current Medium into a Link with lightbox enabled
  150. *
  151. * @param int $width
  152. * @param int $height
  153. * @param bool $reset
  154. * @return MediaLinkInterface
  155. */
  156. public function lightbox($width = null, $height = null, $reset = true);
  157. /**
  158. * Add a class to the element from Markdown or Twig
  159. * Example: ![Example](myimg.png?classes=float-left) or ![Example](myimg.png?classes=myclass1,myclass2)
  160. *
  161. * @return $this
  162. */
  163. public function classes();
  164. /**
  165. * Add an id to the element from Markdown or Twig
  166. * Example: ![Example](myimg.png?id=primary-img)
  167. *
  168. * @param string $id
  169. * @return $this
  170. */
  171. public function id($id);
  172. /**
  173. * Allows to add an inline style attribute from Markdown or Twig
  174. * Example: ![Example](myimg.png?style=float:left)
  175. *
  176. * @param string $style
  177. * @return $this
  178. */
  179. public function style($style);
  180. /**
  181. * Allow any action to be called on this medium from twig or markdown
  182. *
  183. * @param string $method
  184. * @param mixed $args
  185. * @return $this
  186. */
  187. #[\ReturnTypeWillChange]
  188. public function __call($method, $args);
  189. /**
  190. * Set value by using dot notation for nested arrays/objects.
  191. *
  192. * @example $data->set('this.is.my.nested.variable', $value);
  193. *
  194. * @param string $name Dot separated path to the requested value.
  195. * @param mixed $value New value.
  196. * @param string|null $separator Separator, defaults to '.'
  197. * @return $this
  198. */
  199. public function set($name, $value, $separator = null);
  200. }