MediaObjectInterface.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. * Return URL to file.
  142. *
  143. * @param bool $reset
  144. * @return string
  145. */
  146. public function url($reset = true);
  147. /**
  148. * Turn the current Medium into a Link
  149. *
  150. * @param bool $reset
  151. * @param array $attributes
  152. * @return MediaLinkInterface
  153. */
  154. public function link($reset = true, array $attributes = []);
  155. /**
  156. * Turn the current Medium into a Link with lightbox enabled
  157. *
  158. * @param int $width
  159. * @param int $height
  160. * @param bool $reset
  161. * @return MediaLinkInterface
  162. */
  163. public function lightbox($width = null, $height = null, $reset = true);
  164. /**
  165. * Add a class to the element from Markdown or Twig
  166. * Example: ![Example](myimg.png?classes=float-left) or ![Example](myimg.png?classes=myclass1,myclass2)
  167. *
  168. * @return $this
  169. */
  170. public function classes();
  171. /**
  172. * Add an id to the element from Markdown or Twig
  173. * Example: ![Example](myimg.png?id=primary-img)
  174. *
  175. * @param string $id
  176. * @return $this
  177. */
  178. public function id($id);
  179. /**
  180. * Allows to add an inline style attribute from Markdown or Twig
  181. * Example: ![Example](myimg.png?style=float:left)
  182. *
  183. * @param string $style
  184. * @return $this
  185. */
  186. public function style($style);
  187. /**
  188. * Allow any action to be called on this medium from twig or markdown
  189. *
  190. * @param string $method
  191. * @param mixed $args
  192. * @return $this
  193. */
  194. #[\ReturnTypeWillChange]
  195. public function __call($method, $args);
  196. /**
  197. * Get value by using dot notation for nested arrays/objects.
  198. *
  199. * @example $value = $this->get('this.is.my.nested.variable');
  200. *
  201. * @param string $name Dot separated path to the requested value.
  202. * @param mixed $default Default value (or null).
  203. * @param string|null $separator Separator, defaults to '.'
  204. * @return mixed Value.
  205. */
  206. public function get($name, $default = null, $separator = null);
  207. /**
  208. * Set value by using dot notation for nested arrays/objects.
  209. *
  210. * @example $data->set('this.is.my.nested.variable', $value);
  211. *
  212. * @param string $name Dot separated path to the requested value.
  213. * @param mixed $value New value.
  214. * @param string|null $separator Separator, defaults to '.'
  215. * @return $this
  216. */
  217. public function set($name, $value, $separator = null);
  218. }