IMetadataValueWrapper.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\FilesMetadata\Model;
  8. use JsonSerializable;
  9. use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
  10. use OCP\FilesMetadata\Exceptions\FilesMetadataTypeException;
  11. /**
  12. * Model that store the value of a single metadata.
  13. * It stores the value, its type and the index status.
  14. *
  15. * @see IFilesMetadata
  16. * @since 28.0.0
  17. */
  18. interface IMetadataValueWrapper extends JsonSerializable {
  19. /** @since 28.0.0 */
  20. public const TYPE_STRING = 'string';
  21. /** @since 28.0.0 */
  22. public const TYPE_INT = 'int';
  23. /** @since 28.0.0 */
  24. public const TYPE_FLOAT = 'float';
  25. /** @since 28.0.0 */
  26. public const TYPE_BOOL = 'bool';
  27. /** @since 28.0.0 */
  28. public const TYPE_ARRAY = 'array';
  29. /** @since 28.0.0 */
  30. public const TYPE_STRING_LIST = 'string[]';
  31. /** @since 28.0.0 */
  32. public const TYPE_INT_LIST = 'int[]';
  33. /** @since 28.0.0 */
  34. public const EDIT_FORBIDDEN = 0;
  35. /** @since 28.0.0 */
  36. public const EDIT_REQ_OWNERSHIP = 1;
  37. /** @since 28.0.0 */
  38. public const EDIT_REQ_WRITE_PERMISSION = 2;
  39. /** @since 28.0.0 */
  40. public const EDIT_REQ_READ_PERMISSION = 3;
  41. /**
  42. * Unless a call of import() to deserialize an object is expected, a valid value type is needed here.
  43. *
  44. * @param string $type value type
  45. *
  46. * @see self::TYPE_INT
  47. * @see self::TYPE_FLOAT
  48. * @see self::TYPE_BOOL
  49. * @see self::TYPE_ARRAY
  50. * @see self::TYPE_STRING_LIST
  51. * @see self::TYPE_INT_LIST
  52. * @see self::TYPE_STRING
  53. * @since 28.0.0
  54. */
  55. public function __construct(string $type);
  56. /**
  57. * returns the value type
  58. *
  59. * @return string value type
  60. * @see self::TYPE_INT
  61. * @see self::TYPE_FLOAT
  62. * @see self::TYPE_BOOL
  63. * @see self::TYPE_ARRAY
  64. * @see self::TYPE_STRING_LIST
  65. * @see self::TYPE_INT_LIST
  66. * @see self::TYPE_STRING
  67. * @since 28.0.0
  68. */
  69. public function getType(): string;
  70. /**
  71. * returns if the set value type is the one expected
  72. *
  73. * @param string $type value type
  74. *
  75. * @return bool
  76. * @see self::TYPE_INT
  77. * @see self::TYPE_FLOAT
  78. * @see self::TYPE_BOOL
  79. * @see self::TYPE_ARRAY
  80. * @see self::TYPE_STRING_LIST
  81. * @see self::TYPE_INT_LIST
  82. * @see self::TYPE_STRING
  83. * @since 28.0.0
  84. */
  85. public function isType(string $type): bool;
  86. /**
  87. * throws an exception if the type is not correctly set
  88. *
  89. * @param string $type value type
  90. *
  91. * @return self
  92. * @throws FilesMetadataTypeException if type cannot be confirmed
  93. * @see self::TYPE_INT
  94. * @see self::TYPE_BOOL
  95. * @see self::TYPE_ARRAY
  96. * @see self::TYPE_STRING_LIST
  97. * @see self::TYPE_INT_LIST
  98. * @see self::TYPE_STRING
  99. * @see self::TYPE_FLOAT
  100. * @since 28.0.0
  101. */
  102. public function assertType(string $type): self;
  103. /**
  104. * set a string value
  105. *
  106. * @param string $value string to be set as value
  107. *
  108. * @return self
  109. * @throws FilesMetadataTypeException if wrapper was not set to store a string
  110. * @since 28.0.0
  111. */
  112. public function setValueString(string $value): self;
  113. /**
  114. * set a int value
  115. *
  116. * @param int $value int to be set as value
  117. *
  118. * @return self
  119. * @throws FilesMetadataTypeException if wrapper was not set to store an int
  120. * @since 28.0.0
  121. */
  122. public function setValueInt(int $value): self;
  123. /**
  124. * set a float value
  125. *
  126. * @param float $value float to be set as value
  127. *
  128. * @return self
  129. * @throws FilesMetadataTypeException if wrapper was not set to store a float
  130. * @since 28.0.0
  131. */
  132. public function setValueFloat(float $value): self;
  133. /**
  134. * set a bool value
  135. *
  136. * @param bool $value bool to be set as value
  137. *
  138. * @return self
  139. * @throws FilesMetadataTypeException if wrapper was not set to store a bool
  140. * @since 28.0.0
  141. */
  142. public function setValueBool(bool $value): self;
  143. /**
  144. * set an array value
  145. *
  146. * @param array $value array to be set as value
  147. *
  148. * @return self
  149. * @throws FilesMetadataTypeException if wrapper was not set to store an array
  150. * @since 28.0.0
  151. */
  152. public function setValueArray(array $value): self;
  153. /**
  154. * set a string list value
  155. *
  156. * @param string[] $value string list to be set as value
  157. *
  158. * @return self
  159. * @throws FilesMetadataTypeException if wrapper was not set to store a string list
  160. * @since 28.0.0
  161. */
  162. public function setValueStringList(array $value): self;
  163. /**
  164. * set an int list value
  165. *
  166. * @param int[] $value int list to be set as value
  167. *
  168. * @return self
  169. * @throws FilesMetadataTypeException if wrapper was not set to store an int list
  170. * @since 28.0.0
  171. */
  172. public function setValueIntList(array $value): self;
  173. /**
  174. * get stored value
  175. *
  176. * @return string set value
  177. * @throws FilesMetadataTypeException if wrapper was not set to store a string
  178. * @throws FilesMetadataNotFoundException if value is not set
  179. * @since 28.0.0
  180. */
  181. public function getValueString(): string;
  182. /**
  183. * get stored value
  184. *
  185. * @return int set value
  186. * @throws FilesMetadataTypeException if wrapper was not set to store an int
  187. * @throws FilesMetadataNotFoundException if value is not set
  188. * @since 28.0.0
  189. */
  190. public function getValueInt(): int;
  191. /**
  192. * get stored value
  193. *
  194. * @return float set value
  195. * @throws FilesMetadataTypeException if wrapper was not set to store a float
  196. * @throws FilesMetadataNotFoundException if value is not set
  197. * @since 28.0.0
  198. */
  199. public function getValueFloat(): float;
  200. /**
  201. * get stored value
  202. *
  203. * @return bool set value
  204. * @throws FilesMetadataTypeException if wrapper was not set to store a bool
  205. * @throws FilesMetadataNotFoundException if value is not set
  206. * @since 28.0.0
  207. */
  208. public function getValueBool(): bool;
  209. /**
  210. * get stored value
  211. *
  212. * @return array set value
  213. * @throws FilesMetadataTypeException if wrapper was not set to store an array
  214. * @throws FilesMetadataNotFoundException if value is not set
  215. * @since 28.0.0
  216. */
  217. public function getValueArray(): array;
  218. /**
  219. * get stored value
  220. *
  221. * @return string[] set value
  222. * @throws FilesMetadataTypeException if wrapper was not set to store a string list
  223. * @throws FilesMetadataNotFoundException if value is not set
  224. * @since 28.0.0
  225. */
  226. public function getValueStringList(): array;
  227. /**
  228. * get stored value
  229. *
  230. * @return int[] set value
  231. * @throws FilesMetadataTypeException if wrapper was not set to store an int list
  232. * @throws FilesMetadataNotFoundException if value is not set
  233. * @since 28.0.0
  234. */
  235. public function getValueIntList(): array;
  236. /**
  237. * get stored value
  238. *
  239. * @return string|int|float|bool|array|string[]|int[] set value
  240. * @throws FilesMetadataNotFoundException if value is not set
  241. * @since 28.0.0
  242. */
  243. public function getValueAny(): mixed;
  244. /**
  245. * get stored etag value
  246. *
  247. * @return string stored etag
  248. * @since 29.0.0
  249. */
  250. public function getEtag(): string;
  251. /**
  252. * set etag value
  253. *
  254. * @param string $etag etag value
  255. *
  256. * @return self
  257. * @since 29.0.0
  258. */
  259. public function setEtag(string $etag): self;
  260. /**
  261. * @param bool $indexed TRUE to set the stored value as an indexed value
  262. *
  263. * @return self
  264. * @since 28.0.0
  265. */
  266. public function setIndexed(bool $indexed): self;
  267. /**
  268. * returns if value is an indexed value
  269. *
  270. * @return bool TRUE if value is an indexed value
  271. * @since 28.0.0
  272. */
  273. public function isIndexed(): bool;
  274. /**
  275. * set remote edit permission
  276. * (Webdav PROPPATCH)
  277. *
  278. * @param int $permission edit permission
  279. *
  280. * @return self
  281. * @since 28.0.0
  282. */
  283. public function setEditPermission(int $permission): self;
  284. /**
  285. * get remote edit permission
  286. * (Webdav PROPPATCH)
  287. *
  288. * @return int edit permission
  289. * @since 28.0.0
  290. */
  291. public function getEditPermission(): int;
  292. /**
  293. * deserialize the object from a json
  294. *
  295. * @param array $data serialized version of the object
  296. *
  297. * @return self
  298. * @see jsonSerialize
  299. * @since 28.0.0
  300. */
  301. public function import(array $data): self;
  302. }