1
0

AbstractTrashFolder.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Trashbin\Sabre;
  8. use OCA\Files_Trashbin\Trash\ITrashItem;
  9. use OCP\Files\FileInfo;
  10. use Sabre\DAV\Exception\Forbidden;
  11. use Sabre\DAV\Exception\NotFound;
  12. use Sabre\DAV\ICollection;
  13. abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
  14. public function getChildren(): array {
  15. $entries = $this->trashManager->listTrashFolder($this->data);
  16. $children = array_map(function (ITrashItem $entry) {
  17. if ($entry->getType() === FileInfo::TYPE_FOLDER) {
  18. return new TrashFolderFolder($this->trashManager, $entry);
  19. }
  20. return new TrashFolderFile($this->trashManager, $entry);
  21. }, $entries);
  22. return $children;
  23. }
  24. public function getChild($name): ITrash {
  25. $entries = $this->getChildren();
  26. foreach ($entries as $entry) {
  27. if ($entry->getName() === $name) {
  28. return $entry;
  29. }
  30. }
  31. throw new NotFound();
  32. }
  33. public function childExists($name): bool {
  34. try {
  35. $this->getChild($name);
  36. return true;
  37. } catch (NotFound $e) {
  38. return false;
  39. }
  40. }
  41. public function setName($name) {
  42. throw new Forbidden();
  43. }
  44. public function createFile($name, $data = null) {
  45. throw new Forbidden();
  46. }
  47. public function createDirectory($name) {
  48. throw new Forbidden();
  49. }
  50. }