PageRenderTime 62ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/public/files/storage/istorage.php

https://gitlab.com/wuhang2003/core
PHP | 457 lines | 56 code | 49 blank | 352 comment | 0 complexity | 8e0d94106424d4926d8f8f187834f01c MD5 | raw file
  1. <?php
  2. /**
  3. * @author Robin Appelman <icewind@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. /**
  22. * Public interface of ownCloud for apps to use.
  23. * Files/Storage interface
  24. */
  25. // use OCP namespace for all classes that are considered public.
  26. // This means that they should be used by apps instead of the internal ownCloud classes
  27. namespace OCP\Files\Storage;
  28. use OCP\Files\Cache\ICache;
  29. use OCP\Files\Cache\IPropagator;
  30. use OCP\Files\Cache\IScanner;
  31. use OCP\Files\Cache\IUpdater;
  32. use OCP\Files\Cache\IWatcher;
  33. use OCP\Files\InvalidPathException;
  34. /**
  35. * Provide a common interface to all different storage options
  36. *
  37. * All paths passed to the storage are relative to the storage and should NOT have a leading slash.
  38. *
  39. * @since 9.0.0
  40. */
  41. interface IStorage {
  42. /**
  43. * $parameters is a free form array with the configuration options needed to construct the storage
  44. *
  45. * @param array $parameters
  46. * @since 9.0.0
  47. */
  48. public function __construct($parameters);
  49. /**
  50. * Get the identifier for the storage,
  51. * the returned id should be the same for every storage object that is created with the same parameters
  52. * and two storage objects with the same id should refer to two storages that display the same files.
  53. *
  54. * @return string
  55. * @since 9.0.0
  56. */
  57. public function getId();
  58. /**
  59. * see http://php.net/manual/en/function.mkdir.php
  60. * implementations need to implement a recursive mkdir
  61. *
  62. * @param string $path
  63. * @return bool
  64. * @since 9.0.0
  65. */
  66. public function mkdir($path);
  67. /**
  68. * see http://php.net/manual/en/function.rmdir.php
  69. *
  70. * @param string $path
  71. * @return bool
  72. * @since 9.0.0
  73. */
  74. public function rmdir($path);
  75. /**
  76. * see http://php.net/manual/en/function.opendir.php
  77. *
  78. * @param string $path
  79. * @return resource|false
  80. * @since 9.0.0
  81. */
  82. public function opendir($path);
  83. /**
  84. * see http://php.net/manual/en/function.is-dir.php
  85. *
  86. * @param string $path
  87. * @return bool
  88. * @since 9.0.0
  89. */
  90. public function is_dir($path);
  91. /**
  92. * see http://php.net/manual/en/function.is-file.php
  93. *
  94. * @param string $path
  95. * @return bool
  96. * @since 9.0.0
  97. */
  98. public function is_file($path);
  99. /**
  100. * see http://php.net/manual/en/function.stat.php
  101. * only the following keys are required in the result: size and mtime
  102. *
  103. * @param string $path
  104. * @return array|false
  105. * @since 9.0.0
  106. */
  107. public function stat($path);
  108. /**
  109. * see http://php.net/manual/en/function.filetype.php
  110. *
  111. * @param string $path
  112. * @return string|false
  113. * @since 9.0.0
  114. */
  115. public function filetype($path);
  116. /**
  117. * see http://php.net/manual/en/function.filesize.php
  118. * The result for filesize when called on a folder is required to be 0
  119. *
  120. * @param string $path
  121. * @return int|false
  122. * @since 9.0.0
  123. */
  124. public function filesize($path);
  125. /**
  126. * check if a file can be created in $path
  127. *
  128. * @param string $path
  129. * @return bool
  130. * @since 9.0.0
  131. */
  132. public function isCreatable($path);
  133. /**
  134. * check if a file can be read
  135. *
  136. * @param string $path
  137. * @return bool
  138. * @since 9.0.0
  139. */
  140. public function isReadable($path);
  141. /**
  142. * check if a file can be written to
  143. *
  144. * @param string $path
  145. * @return bool
  146. * @since 9.0.0
  147. */
  148. public function isUpdatable($path);
  149. /**
  150. * check if a file can be deleted
  151. *
  152. * @param string $path
  153. * @return bool
  154. * @since 9.0.0
  155. */
  156. public function isDeletable($path);
  157. /**
  158. * check if a file can be shared
  159. *
  160. * @param string $path
  161. * @return bool
  162. * @since 9.0.0
  163. */
  164. public function isSharable($path);
  165. /**
  166. * get the full permissions of a path.
  167. * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
  168. *
  169. * @param string $path
  170. * @return int
  171. * @since 9.0.0
  172. */
  173. public function getPermissions($path);
  174. /**
  175. * see http://php.net/manual/en/function.file_exists.php
  176. *
  177. * @param string $path
  178. * @return bool
  179. * @since 9.0.0
  180. */
  181. public function file_exists($path);
  182. /**
  183. * see http://php.net/manual/en/function.filemtime.php
  184. *
  185. * @param string $path
  186. * @return int|false
  187. * @since 9.0.0
  188. */
  189. public function filemtime($path);
  190. /**
  191. * see http://php.net/manual/en/function.file_get_contents.php
  192. *
  193. * @param string $path
  194. * @return string|false
  195. * @since 9.0.0
  196. */
  197. public function file_get_contents($path);
  198. /**
  199. * see http://php.net/manual/en/function.file_put_contents.php
  200. *
  201. * @param string $path
  202. * @param string $data
  203. * @return bool
  204. * @since 9.0.0
  205. */
  206. public function file_put_contents($path, $data);
  207. /**
  208. * see http://php.net/manual/en/function.unlink.php
  209. *
  210. * @param string $path
  211. * @return bool
  212. * @since 9.0.0
  213. */
  214. public function unlink($path);
  215. /**
  216. * see http://php.net/manual/en/function.rename.php
  217. *
  218. * @param string $path1
  219. * @param string $path2
  220. * @return bool
  221. * @since 9.0.0
  222. */
  223. public function rename($path1, $path2);
  224. /**
  225. * see http://php.net/manual/en/function.copy.php
  226. *
  227. * @param string $path1
  228. * @param string $path2
  229. * @return bool
  230. * @since 9.0.0
  231. */
  232. public function copy($path1, $path2);
  233. /**
  234. * see http://php.net/manual/en/function.fopen.php
  235. *
  236. * @param string $path
  237. * @param string $mode
  238. * @return resource|false
  239. * @since 9.0.0
  240. */
  241. public function fopen($path, $mode);
  242. /**
  243. * get the mimetype for a file or folder
  244. * The mimetype for a folder is required to be "httpd/unix-directory"
  245. *
  246. * @param string $path
  247. * @return string|false
  248. * @since 9.0.0
  249. */
  250. public function getMimeType($path);
  251. /**
  252. * see http://php.net/manual/en/function.hash-file.php
  253. *
  254. * @param string $type
  255. * @param string $path
  256. * @param bool $raw
  257. * @return string|false
  258. * @since 9.0.0
  259. */
  260. public function hash($type, $path, $raw = false);
  261. /**
  262. * see http://php.net/manual/en/function.free_space.php
  263. *
  264. * @param string $path
  265. * @return int|false
  266. * @since 9.0.0
  267. */
  268. public function free_space($path);
  269. /**
  270. * see http://php.net/manual/en/function.touch.php
  271. * If the backend does not support the operation, false should be returned
  272. *
  273. * @param string $path
  274. * @param int $mtime
  275. * @return bool
  276. * @since 9.0.0
  277. */
  278. public function touch($path, $mtime = null);
  279. /**
  280. * get the path to a local version of the file.
  281. * The local version of the file can be temporary and doesn't have to be persistent across requests
  282. *
  283. * @param string $path
  284. * @return string|false
  285. * @since 9.0.0
  286. */
  287. public function getLocalFile($path);
  288. /**
  289. * check if a file or folder has been updated since $time
  290. *
  291. * @param string $path
  292. * @param int $time
  293. * @return bool
  294. * @since 9.0.0
  295. *
  296. * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
  297. * returning true for other changes in the folder is optional
  298. */
  299. public function hasUpdated($path, $time);
  300. /**
  301. * get the ETag for a file or folder
  302. *
  303. * @param string $path
  304. * @return string|false
  305. * @since 9.0.0
  306. */
  307. public function getETag($path);
  308. /**
  309. * Returns whether the storage is local, which means that files
  310. * are stored on the local filesystem instead of remotely.
  311. * Calling getLocalFile() for local storages should always
  312. * return the local files, whereas for non-local storages
  313. * it might return a temporary file.
  314. *
  315. * @return bool true if the files are stored locally, false otherwise
  316. * @since 9.0.0
  317. */
  318. public function isLocal();
  319. /**
  320. * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
  321. *
  322. * @param string $class
  323. * @return bool
  324. * @since 9.0.0
  325. */
  326. public function instanceOfStorage($class);
  327. /**
  328. * A custom storage implementation can return an url for direct download of a give file.
  329. *
  330. * For now the returned array can hold the parameter url - in future more attributes might follow.
  331. *
  332. * @param string $path
  333. * @return array|false
  334. * @since 9.0.0
  335. */
  336. public function getDirectDownload($path);
  337. /**
  338. * @param string $path the path of the target folder
  339. * @param string $fileName the name of the file itself
  340. * @return void
  341. * @throws InvalidPathException
  342. * @since 9.0.0
  343. */
  344. public function verifyPath($path, $fileName);
  345. /**
  346. * @param \OCP\Files\Storage $sourceStorage
  347. * @param string $sourceInternalPath
  348. * @param string $targetInternalPath
  349. * @return bool
  350. * @since 9.0.0
  351. */
  352. public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath);
  353. /**
  354. * @param \OCP\Files\Storage $sourceStorage
  355. * @param string $sourceInternalPath
  356. * @param string $targetInternalPath
  357. * @return bool
  358. * @since 9.0.0
  359. */
  360. public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath);
  361. /**
  362. * Test a storage for availability
  363. *
  364. * @since 9.0.0
  365. * @return bool
  366. */
  367. public function test();
  368. /**
  369. * @since 9.0.0
  370. * @return array [ available, last_checked ]
  371. */
  372. public function getAvailability();
  373. /**
  374. * @since 9.0.0
  375. * @param bool $isAvailable
  376. */
  377. public function setAvailability($isAvailable);
  378. /**
  379. * @param string $path path for which to retrieve the owner
  380. * @since 9.0.0
  381. */
  382. public function getOwner($path);
  383. /**
  384. * @return ICache
  385. * @since 9.0.0
  386. */
  387. public function getCache();
  388. /**
  389. * @return IPropagator
  390. * @since 9.0.0
  391. */
  392. public function getPropagator();
  393. /**
  394. * @return IScanner
  395. * @since 9.0.0
  396. */
  397. public function getScanner();
  398. /**
  399. * @return IUpdater
  400. * @since 9.0.0
  401. */
  402. public function getUpdater();
  403. /**
  404. * @return IWatcher
  405. * @since 9.0.0
  406. */
  407. public function getWatcher();
  408. }