PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/private/files/storage/wrapper/wrapper.php

https://github.com/JasonEades/core
PHP | 454 lines | 134 code | 46 blank | 274 comment | 0 complexity | c21e99349754503e8b1cba887b6124be MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, Apache-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Files\Storage\Wrapper;
  9. class Wrapper implements \OC\Files\Storage\Storage {
  10. /**
  11. * @var \OC\Files\Storage\Storage $storage
  12. */
  13. protected $storage;
  14. /**
  15. * @param array $parameters
  16. */
  17. public function __construct($parameters) {
  18. $this->storage = $parameters['storage'];
  19. }
  20. /**
  21. * @return \OC\Files\Storage\Storage
  22. */
  23. public function getWrapperStorage() {
  24. return $this->storage;
  25. }
  26. /**
  27. * Get the identifier for the storage,
  28. * the returned id should be the same for every storage object that is created with the same parameters
  29. * and two storage objects with the same id should refer to two storages that display the same files.
  30. *
  31. * @return string
  32. */
  33. public function getId() {
  34. return $this->storage->getId();
  35. }
  36. /**
  37. * see http://php.net/manual/en/function.mkdir.php
  38. *
  39. * @param string $path
  40. * @return bool
  41. */
  42. public function mkdir($path) {
  43. return $this->storage->mkdir($path);
  44. }
  45. /**
  46. * see http://php.net/manual/en/function.rmdir.php
  47. *
  48. * @param string $path
  49. * @return bool
  50. */
  51. public function rmdir($path) {
  52. return $this->storage->rmdir($path);
  53. }
  54. /**
  55. * see http://php.net/manual/en/function.opendir.php
  56. *
  57. * @param string $path
  58. * @return resource
  59. */
  60. public function opendir($path) {
  61. return $this->storage->opendir($path);
  62. }
  63. /**
  64. * see http://php.net/manual/en/function.is_dir.php
  65. *
  66. * @param string $path
  67. * @return bool
  68. */
  69. public function is_dir($path) {
  70. return $this->storage->is_dir($path);
  71. }
  72. /**
  73. * see http://php.net/manual/en/function.is_file.php
  74. *
  75. * @param string $path
  76. * @return bool
  77. */
  78. public function is_file($path) {
  79. return $this->storage->is_file($path);
  80. }
  81. /**
  82. * see http://php.net/manual/en/function.stat.php
  83. * only the following keys are required in the result: size and mtime
  84. *
  85. * @param string $path
  86. * @return array
  87. */
  88. public function stat($path) {
  89. return $this->storage->stat($path);
  90. }
  91. /**
  92. * see http://php.net/manual/en/function.filetype.php
  93. *
  94. * @param string $path
  95. * @return bool
  96. */
  97. public function filetype($path) {
  98. return $this->storage->filetype($path);
  99. }
  100. /**
  101. * see http://php.net/manual/en/function.filesize.php
  102. * The result for filesize when called on a folder is required to be 0
  103. *
  104. * @param string $path
  105. * @return int
  106. */
  107. public function filesize($path) {
  108. return $this->storage->filesize($path);
  109. }
  110. /**
  111. * check if a file can be created in $path
  112. *
  113. * @param string $path
  114. * @return bool
  115. */
  116. public function isCreatable($path) {
  117. return $this->storage->isCreatable($path);
  118. }
  119. /**
  120. * check if a file can be read
  121. *
  122. * @param string $path
  123. * @return bool
  124. */
  125. public function isReadable($path) {
  126. return $this->storage->isReadable($path);
  127. }
  128. /**
  129. * check if a file can be written to
  130. *
  131. * @param string $path
  132. * @return bool
  133. */
  134. public function isUpdatable($path) {
  135. return $this->storage->isUpdatable($path);
  136. }
  137. /**
  138. * check if a file can be deleted
  139. *
  140. * @param string $path
  141. * @return bool
  142. */
  143. public function isDeletable($path) {
  144. return $this->storage->isDeletable($path);
  145. }
  146. /**
  147. * check if a file can be shared
  148. *
  149. * @param string $path
  150. * @return bool
  151. */
  152. public function isSharable($path) {
  153. return $this->storage->isSharable($path);
  154. }
  155. /**
  156. * get the full permissions of a path.
  157. * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
  158. *
  159. * @param string $path
  160. * @return int
  161. */
  162. public function getPermissions($path) {
  163. return $this->storage->getPermissions($path);
  164. }
  165. /**
  166. * see http://php.net/manual/en/function.file_exists.php
  167. *
  168. * @param string $path
  169. * @return bool
  170. */
  171. public function file_exists($path) {
  172. return $this->storage->file_exists($path);
  173. }
  174. /**
  175. * see http://php.net/manual/en/function.filemtime.php
  176. *
  177. * @param string $path
  178. * @return int
  179. */
  180. public function filemtime($path) {
  181. return $this->storage->filemtime($path);
  182. }
  183. /**
  184. * see http://php.net/manual/en/function.file_get_contents.php
  185. *
  186. * @param string $path
  187. * @return string
  188. */
  189. public function file_get_contents($path) {
  190. return $this->storage->file_get_contents($path);
  191. }
  192. /**
  193. * see http://php.net/manual/en/function.file_put_contents.php
  194. *
  195. * @param string $path
  196. * @param string $data
  197. * @return bool
  198. */
  199. public function file_put_contents($path, $data) {
  200. return $this->storage->file_put_contents($path, $data);
  201. }
  202. /**
  203. * see http://php.net/manual/en/function.unlink.php
  204. *
  205. * @param string $path
  206. * @return bool
  207. */
  208. public function unlink($path) {
  209. return $this->storage->unlink($path);
  210. }
  211. /**
  212. * see http://php.net/manual/en/function.rename.php
  213. *
  214. * @param string $path1
  215. * @param string $path2
  216. * @return bool
  217. */
  218. public function rename($path1, $path2) {
  219. return $this->storage->rename($path1, $path2);
  220. }
  221. /**
  222. * see http://php.net/manual/en/function.copy.php
  223. *
  224. * @param string $path1
  225. * @param string $path2
  226. * @return bool
  227. */
  228. public function copy($path1, $path2) {
  229. return $this->storage->copy($path1, $path2);
  230. }
  231. /**
  232. * see http://php.net/manual/en/function.fopen.php
  233. *
  234. * @param string $path
  235. * @param string $mode
  236. * @return resource
  237. */
  238. public function fopen($path, $mode) {
  239. return $this->storage->fopen($path, $mode);
  240. }
  241. /**
  242. * get the mimetype for a file or folder
  243. * The mimetype for a folder is required to be "httpd/unix-directory"
  244. *
  245. * @param string $path
  246. * @return string
  247. */
  248. public function getMimeType($path) {
  249. return $this->storage->getMimeType($path);
  250. }
  251. /**
  252. * see http://php.net/manual/en/function.hash.php
  253. *
  254. * @param string $type
  255. * @param string $path
  256. * @param bool $raw
  257. * @return string
  258. */
  259. public function hash($type, $path, $raw = false) {
  260. return $this->storage->hash($type, $path, $raw);
  261. }
  262. /**
  263. * see http://php.net/manual/en/function.free_space.php
  264. *
  265. * @param string $path
  266. * @return int
  267. */
  268. public function free_space($path) {
  269. return $this->storage->free_space($path);
  270. }
  271. /**
  272. * search for occurrences of $query in file names
  273. *
  274. * @param string $query
  275. * @return array
  276. */
  277. public function search($query) {
  278. return $this->storage->search($query);
  279. }
  280. /**
  281. * see http://php.net/manual/en/function.touch.php
  282. * If the backend does not support the operation, false should be returned
  283. *
  284. * @param string $path
  285. * @param int $mtime
  286. * @return bool
  287. */
  288. public function touch($path, $mtime = null) {
  289. return $this->storage->touch($path, $mtime);
  290. }
  291. /**
  292. * get the path to a local version of the file.
  293. * The local version of the file can be temporary and doesn't have to be persistent across requests
  294. *
  295. * @param string $path
  296. * @return string
  297. */
  298. public function getLocalFile($path) {
  299. return $this->storage->getLocalFile($path);
  300. }
  301. /**
  302. * get the path to a local version of the folder.
  303. * The local version of the folder can be temporary and doesn't have to be persistent across requests
  304. *
  305. * @param string $path
  306. * @return string
  307. */
  308. public function getLocalFolder($path) {
  309. return $this->storage->getLocalFolder($path);
  310. }
  311. /**
  312. * check if a file or folder has been updated since $time
  313. *
  314. * @param string $path
  315. * @param int $time
  316. * @return bool
  317. *
  318. * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
  319. * returning true for other changes in the folder is optional
  320. */
  321. public function hasUpdated($path, $time) {
  322. return $this->storage->hasUpdated($path, $time);
  323. }
  324. /**
  325. * get a cache instance for the storage
  326. *
  327. * @param string $path
  328. * @return \OC\Files\Cache\Cache
  329. */
  330. public function getCache($path = '') {
  331. return $this->storage->getCache($path);
  332. }
  333. /**
  334. * get a scanner instance for the storage
  335. *
  336. * @param string $path
  337. * @return \OC\Files\Cache\Scanner
  338. */
  339. public function getScanner($path = '') {
  340. return $this->storage->getScanner($path);
  341. }
  342. /**
  343. * get the user id of the owner of a file or folder
  344. *
  345. * @param string $path
  346. * @return string
  347. */
  348. public function getOwner($path) {
  349. return $this->storage->getOwner($path);
  350. }
  351. /**
  352. * get a watcher instance for the cache
  353. *
  354. * @param string $path
  355. * @return \OC\Files\Cache\Watcher
  356. */
  357. public function getWatcher($path = '') {
  358. return $this->storage->getWatcher($path);
  359. }
  360. /**
  361. * @return \OC\Files\Cache\Storage
  362. */
  363. public function getStorageCache() {
  364. return $this->storage->getStorageCache();
  365. }
  366. /**
  367. * get the ETag for a file or folder
  368. *
  369. * @param string $path
  370. * @return string
  371. */
  372. public function getETag($path) {
  373. return $this->storage->getETag($path);
  374. }
  375. /**
  376. * Returns true
  377. * @return true
  378. */
  379. public function test() {
  380. return $this->storage->test();
  381. }
  382. /**
  383. * Returns the wrapped storage's value for isLocal()
  384. * @return bool wrapped storage's isLocal() value
  385. */
  386. public function isLocal() {
  387. return $this->storage->isLocal();
  388. }
  389. /**
  390. * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
  391. *
  392. * @param string $class
  393. * @return bool
  394. */
  395. public function instanceOfStorage($class) {
  396. return is_a($this, $class) or $this->storage->instanceOfStorage($class);
  397. }
  398. /**
  399. * Pass any methods custom to specific storage implementations to the wrapped storage
  400. *
  401. * @param string $method
  402. * @param array $args
  403. * @return mixed
  404. */
  405. public function __call($method, $args) {
  406. return call_user_func_array(array($this->storage, $method), $args);
  407. }
  408. }