LazyRoot.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Files\Node;
  23. use OC\Files\Mount\MountPoint;
  24. use OCP\Files\IRootFolder;
  25. use OCP\Files\NotPermittedException;
  26. /**
  27. * Class LazyRoot
  28. *
  29. * This is a lazy wrapper around the root. So only
  30. * once it is needed this will get initialized.
  31. *
  32. * @package OC\Files\Node
  33. */
  34. class LazyRoot implements IRootFolder {
  35. /** @var \Closure */
  36. private $rootFolderClosure;
  37. /** @var IRootFolder */
  38. private $rootFolder;
  39. /**
  40. * LazyRoot constructor.
  41. *
  42. * @param \Closure $rootFolderClosure
  43. */
  44. public function __construct(\Closure $rootFolderClosure) {
  45. $this->rootFolderClosure = $rootFolderClosure;
  46. }
  47. /**
  48. * Magic method to first get the real rootFolder and then
  49. * call $method with $args on it
  50. *
  51. * @param $method
  52. * @param $args
  53. * @return mixed
  54. */
  55. public function __call($method, $args) {
  56. if ($this->rootFolder === null) {
  57. $this->rootFolder = call_user_func($this->rootFolderClosure);
  58. }
  59. return call_user_func_array([$this->rootFolder, $method], $args);
  60. }
  61. /**
  62. * @inheritDoc
  63. */
  64. public function getUser() {
  65. return $this->__call(__FUNCTION__, func_get_args());
  66. }
  67. /**
  68. * @inheritDoc
  69. */
  70. public function listen($scope, $method, callable $callback) {
  71. $this->__call(__FUNCTION__, func_get_args());
  72. }
  73. /**
  74. * @inheritDoc
  75. */
  76. public function removeListener($scope = null, $method = null, callable $callback = null) {
  77. $this->__call(__FUNCTION__, func_get_args());
  78. }
  79. /**
  80. * @inheritDoc
  81. */
  82. public function emit($scope, $method, $arguments = array()) {
  83. $this->__call(__FUNCTION__, func_get_args());
  84. }
  85. /**
  86. * @inheritDoc
  87. */
  88. public function mount($storage, $mountPoint, $arguments = array()) {
  89. $this->__call(__FUNCTION__, func_get_args());
  90. }
  91. /**
  92. * @inheritDoc
  93. */
  94. public function getMount($mountPoint) {
  95. return $this->__call(__FUNCTION__, func_get_args());
  96. }
  97. /**
  98. * @inheritDoc
  99. */
  100. public function getMountsIn($mountPoint) {
  101. return $this->__call(__FUNCTION__, func_get_args());
  102. }
  103. /**
  104. * @inheritDoc
  105. */
  106. public function getMountByStorageId($storageId) {
  107. return $this->__call(__FUNCTION__, func_get_args());
  108. }
  109. /**
  110. * @inheritDoc
  111. */
  112. public function getMountByNumericStorageId($numericId) {
  113. return $this->__call(__FUNCTION__, func_get_args());
  114. }
  115. /**
  116. * @inheritDoc
  117. */
  118. public function unMount($mount) {
  119. $this->__call(__FUNCTION__, func_get_args());
  120. }
  121. /**
  122. * @inheritDoc
  123. */
  124. public function get($path) {
  125. return $this->__call(__FUNCTION__, func_get_args());
  126. }
  127. /**
  128. * @inheritDoc
  129. */
  130. public function rename($targetPath) {
  131. return $this->__call(__FUNCTION__, func_get_args());
  132. }
  133. /**
  134. * @inheritDoc
  135. */
  136. public function delete() {
  137. return $this->__call(__FUNCTION__, func_get_args());
  138. }
  139. /**
  140. * @inheritDoc
  141. */
  142. public function copy($targetPath) {
  143. return $this->__call(__FUNCTION__, func_get_args());
  144. }
  145. /**
  146. * @inheritDoc
  147. */
  148. public function touch($mtime = null) {
  149. $this->__call(__FUNCTION__, func_get_args());
  150. }
  151. /**
  152. * @inheritDoc
  153. */
  154. public function getStorage() {
  155. return $this->__call(__FUNCTION__, func_get_args());
  156. }
  157. /**
  158. * @inheritDoc
  159. */
  160. public function getPath() {
  161. return $this->__call(__FUNCTION__, func_get_args());
  162. }
  163. /**
  164. * @inheritDoc
  165. */
  166. public function getInternalPath() {
  167. return $this->__call(__FUNCTION__, func_get_args());
  168. }
  169. /**
  170. * @inheritDoc
  171. */
  172. public function getId() {
  173. return $this->__call(__FUNCTION__, func_get_args());
  174. }
  175. /**
  176. * @inheritDoc
  177. */
  178. public function stat() {
  179. return $this->__call(__FUNCTION__, func_get_args());
  180. }
  181. /**
  182. * @inheritDoc
  183. */
  184. public function getMTime() {
  185. return $this->__call(__FUNCTION__, func_get_args());
  186. }
  187. /**
  188. * @inheritDoc
  189. */
  190. public function getSize() {
  191. return $this->__call(__FUNCTION__, func_get_args());
  192. }
  193. /**
  194. * @inheritDoc
  195. */
  196. public function getEtag() {
  197. return $this->__call(__FUNCTION__, func_get_args());
  198. }
  199. /**
  200. * @inheritDoc
  201. */
  202. public function getPermissions() {
  203. return $this->__call(__FUNCTION__, func_get_args());
  204. }
  205. /**
  206. * @inheritDoc
  207. */
  208. public function isReadable() {
  209. return $this->__call(__FUNCTION__, func_get_args());
  210. }
  211. /**
  212. * @inheritDoc
  213. */
  214. public function isUpdateable() {
  215. return $this->__call(__FUNCTION__, func_get_args());
  216. }
  217. /**
  218. * @inheritDoc
  219. */
  220. public function isDeletable() {
  221. return $this->__call(__FUNCTION__, func_get_args());
  222. }
  223. /**
  224. * @inheritDoc
  225. */
  226. public function isShareable() {
  227. return $this->__call(__FUNCTION__, func_get_args());
  228. }
  229. /**
  230. * @inheritDoc
  231. */
  232. public function getParent() {
  233. return $this->__call(__FUNCTION__, func_get_args());
  234. }
  235. /**
  236. * @inheritDoc
  237. */
  238. public function getName() {
  239. return $this->__call(__FUNCTION__, func_get_args());
  240. }
  241. /**
  242. * @inheritDoc
  243. */
  244. public function getUserFolder($userId) {
  245. return $this->__call(__FUNCTION__, func_get_args());
  246. }
  247. /**
  248. * @inheritDoc
  249. */
  250. public function getMimetype() {
  251. return $this->__call(__FUNCTION__, func_get_args());
  252. }
  253. /**
  254. * @inheritDoc
  255. */
  256. public function getMimePart() {
  257. return $this->__call(__FUNCTION__, func_get_args());
  258. }
  259. /**
  260. * @inheritDoc
  261. */
  262. public function isEncrypted() {
  263. return $this->__call(__FUNCTION__, func_get_args());
  264. }
  265. /**
  266. * @inheritDoc
  267. */
  268. public function getType() {
  269. return $this->__call(__FUNCTION__, func_get_args());
  270. }
  271. /**
  272. * @inheritDoc
  273. */
  274. public function isShared() {
  275. return $this->__call(__FUNCTION__, func_get_args());
  276. }
  277. /**
  278. * @inheritDoc
  279. */
  280. public function isMounted() {
  281. return $this->__call(__FUNCTION__, func_get_args());
  282. }
  283. /**
  284. * @inheritDoc
  285. */
  286. public function getMountPoint() {
  287. return $this->__call(__FUNCTION__, func_get_args());
  288. }
  289. /**
  290. * @inheritDoc
  291. */
  292. public function getOwner() {
  293. return $this->__call(__FUNCTION__, func_get_args());
  294. }
  295. /**
  296. * @inheritDoc
  297. */
  298. public function getChecksum() {
  299. return $this->__call(__FUNCTION__, func_get_args());
  300. }
  301. /**
  302. * @inheritDoc
  303. */
  304. public function getFullPath($path) {
  305. return $this->__call(__FUNCTION__, func_get_args());
  306. }
  307. /**
  308. * @inheritDoc
  309. */
  310. public function getRelativePath($path) {
  311. return $this->__call(__FUNCTION__, func_get_args());
  312. }
  313. /**
  314. * @inheritDoc
  315. */
  316. public function isSubNode($node) {
  317. return $this->__call(__FUNCTION__, func_get_args());
  318. }
  319. /**
  320. * @inheritDoc
  321. */
  322. public function getDirectoryListing() {
  323. return $this->__call(__FUNCTION__, func_get_args());
  324. }
  325. /**
  326. * @inheritDoc
  327. */
  328. public function nodeExists($path) {
  329. return $this->__call(__FUNCTION__, func_get_args());
  330. }
  331. /**
  332. * @inheritDoc
  333. */
  334. public function newFolder($path) {
  335. return $this->__call(__FUNCTION__, func_get_args());
  336. }
  337. /**
  338. * @inheritDoc
  339. */
  340. public function newFile($path) {
  341. return $this->__call(__FUNCTION__, func_get_args());
  342. }
  343. /**
  344. * @inheritDoc
  345. */
  346. public function search($query) {
  347. return $this->__call(__FUNCTION__, func_get_args());
  348. }
  349. /**
  350. * @inheritDoc
  351. */
  352. public function searchByMime($mimetype) {
  353. return $this->__call(__FUNCTION__, func_get_args());
  354. }
  355. /**
  356. * @inheritDoc
  357. */
  358. public function searchByTag($tag, $userId) {
  359. return $this->__call(__FUNCTION__, func_get_args());
  360. }
  361. /**
  362. * @inheritDoc
  363. */
  364. public function getById($id) {
  365. return $this->__call(__FUNCTION__, func_get_args());
  366. }
  367. /**
  368. * @inheritDoc
  369. */
  370. public function getFreeSpace() {
  371. return $this->__call(__FUNCTION__, func_get_args());
  372. }
  373. /**
  374. * @inheritDoc
  375. */
  376. public function isCreatable() {
  377. return $this->__call(__FUNCTION__, func_get_args());
  378. }
  379. /**
  380. * @inheritDoc
  381. */
  382. public function getNonExistingName($name) {
  383. return $this->__call(__FUNCTION__, func_get_args());
  384. }
  385. /**
  386. * @inheritDoc
  387. */
  388. public function move($targetPath) {
  389. return $this->__call(__FUNCTION__, func_get_args());
  390. }
  391. /**
  392. * @inheritDoc
  393. */
  394. public function lock($type) {
  395. return $this->__call(__FUNCTION__, func_get_args());
  396. }
  397. /**
  398. * @inheritDoc
  399. */
  400. public function changeLock($targetType) {
  401. return $this->__call(__FUNCTION__, func_get_args());
  402. }
  403. /**
  404. * @inheritDoc
  405. */
  406. public function unlock($type) {
  407. return $this->__call(__FUNCTION__, func_get_args());
  408. }
  409. /**
  410. * @inheritDoc
  411. */
  412. public function getRecent($limit, $offset = 0) {
  413. return $this->__call(__FUNCTION__, func_get_args());
  414. }
  415. }