Folder.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP\Files;
  10. use OCP\Files\Search\ISearchQuery;
  11. /**
  12. * @since 6.0.0
  13. */
  14. interface Folder extends Node {
  15. /**
  16. * Get the full path of an item in the folder within owncloud's filesystem
  17. *
  18. * @param string $path relative path of an item in the folder
  19. * @return string
  20. * @throws \OCP\Files\NotPermittedException
  21. * @since 6.0.0
  22. */
  23. public function getFullPath($path);
  24. /**
  25. * Get the path of an item in the folder relative to the folder
  26. *
  27. * @param string $path absolute path of an item in the folder
  28. * @throws \OCP\Files\NotFoundException
  29. * @return string|null
  30. * @since 6.0.0
  31. */
  32. public function getRelativePath($path);
  33. /**
  34. * check if a node is a (grand-)child of the folder
  35. *
  36. * @param \OCP\Files\Node $node
  37. * @return bool
  38. * @since 6.0.0
  39. */
  40. public function isSubNode($node);
  41. /**
  42. * get the content of this directory
  43. *
  44. * @throws \OCP\Files\NotFoundException
  45. * @return \OCP\Files\Node[]
  46. * @since 6.0.0
  47. */
  48. public function getDirectoryListing();
  49. /**
  50. * Get the node at $path
  51. *
  52. * @param string $path relative path of the file or folder
  53. * @return \OCP\Files\Node
  54. * @throws \OCP\Files\NotFoundException
  55. * @throws \OCP\Files\NotPermittedException
  56. * @since 6.0.0
  57. */
  58. public function get($path);
  59. /**
  60. * Check if a file or folder exists in the folder
  61. *
  62. * @param string $path relative path of the file or folder
  63. * @return bool
  64. * @since 6.0.0
  65. */
  66. public function nodeExists($path);
  67. /**
  68. * Create a new folder
  69. *
  70. * @param string $path relative path of the new folder
  71. * @return \OCP\Files\Folder
  72. * @throws \OCP\Files\NotPermittedException
  73. * @since 6.0.0
  74. */
  75. public function newFolder($path);
  76. /**
  77. * Create a new file
  78. *
  79. * @param string $path relative path of the new file
  80. * @param string|resource|null $content content for the new file, since 19.0.0
  81. * @return \OCP\Files\File
  82. * @throws \OCP\Files\NotPermittedException
  83. * @since 6.0.0
  84. */
  85. public function newFile($path, $content = null);
  86. /**
  87. * search for files with the name matching $query
  88. *
  89. * @param string|ISearchQuery $query
  90. * @return \OCP\Files\Node[]
  91. * @since 6.0.0
  92. */
  93. public function search($query);
  94. /**
  95. * search for files by mimetype
  96. * $mimetype can either be a full mimetype (image/png) or a wildcard mimetype (image)
  97. *
  98. * @param string $mimetype
  99. * @return \OCP\Files\Node[]
  100. * @since 6.0.0
  101. */
  102. public function searchByMime($mimetype);
  103. /**
  104. * search for files by tag
  105. *
  106. * @param string|int $tag tag name or tag id
  107. * @param string $userId owner of the tags
  108. * @return \OCP\Files\Node[]
  109. * @since 8.0.0
  110. */
  111. public function searchByTag($tag, $userId);
  112. /**
  113. * search for files by system tag
  114. *
  115. * @param string|int $tag tag name
  116. * @param string $userId user id to ensure access on returned nodes
  117. * @return \OCP\Files\Node[]
  118. * @since 28.0.0
  119. */
  120. public function searchBySystemTag(string $tagName, string $userId, int $limit = 0, int $offset = 0);
  121. /**
  122. * get a file or folder inside the folder by its internal id
  123. *
  124. * This method could return multiple entries. For example once the file/folder
  125. * is shared or mounted (files_external) to the user multiple times.
  126. *
  127. * Note that the different entries can have different permissions.
  128. *
  129. * @param int $id
  130. * @return \OCP\Files\Node[]
  131. * @since 6.0.0
  132. */
  133. public function getById($id);
  134. /**
  135. * get a file or folder inside the folder by its internal id
  136. *
  137. * Unlike getById, this method only returns a single node even if the user has
  138. * access to the file with the requested id multiple times.
  139. *
  140. * This method provides no guarantee about which of the nodes in returned and the
  141. * returned node might, for example, have less permissions than other nodes for the same file
  142. *
  143. * Apps that require accurate information about the users access to the file should use getById
  144. * instead of pick the correct node out of the result.
  145. *
  146. * @param int $id
  147. * @return Node|null
  148. * @since 29.0.0
  149. */
  150. public function getFirstNodeById(int $id): ?Node;
  151. /**
  152. * Get the amount of free space inside the folder
  153. *
  154. * @return int
  155. * @since 6.0.0
  156. */
  157. public function getFreeSpace();
  158. /**
  159. * Check if new files or folders can be created within the folder
  160. *
  161. * @return bool
  162. * @since 6.0.0
  163. */
  164. public function isCreatable();
  165. /**
  166. * Add a suffix to the name in case the file exists
  167. *
  168. * @param string $name
  169. * @return string
  170. * @throws NotPermittedException
  171. * @since 8.1.0
  172. */
  173. public function getNonExistingName($name);
  174. /**
  175. * @param int $limit
  176. * @param int $offset
  177. * @return \OCP\Files\Node[]
  178. * @since 9.1.0
  179. */
  180. public function getRecent($limit, $offset = 0);
  181. }