You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

499 lines
9.1 KiB

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