IMetadataValueWrapper.php 8.1 KB

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