1
0

AbstractTrashFolder.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  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
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OCA\Files_Trashbin\Sabre;
  23. use OCA\Files_Trashbin\Trash\ITrashItem;
  24. use OCP\Files\FileInfo;
  25. use Sabre\DAV\Exception\Forbidden;
  26. use Sabre\DAV\Exception\NotFound;
  27. use Sabre\DAV\ICollection;
  28. abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
  29. public function getChildren(): array {
  30. $entries = $this->trashManager->listTrashFolder($this->data);
  31. $children = array_map(function (ITrashItem $entry) {
  32. if ($entry->getType() === FileInfo::TYPE_FOLDER) {
  33. return new TrashFolderFolder($this->trashManager, $entry);
  34. }
  35. return new TrashFolderFile($this->trashManager, $entry);
  36. }, $entries);
  37. return $children;
  38. }
  39. public function getChild($name): ITrash {
  40. $entries = $this->getChildren();
  41. foreach ($entries as $entry) {
  42. if ($entry->getName() === $name) {
  43. return $entry;
  44. }
  45. }
  46. throw new NotFound();
  47. }
  48. public function childExists($name): bool {
  49. try {
  50. $this->getChild($name);
  51. return true;
  52. } catch (NotFound $e) {
  53. return false;
  54. }
  55. }
  56. public function setName($name) {
  57. throw new Forbidden();
  58. }
  59. public function createFile($name, $data = null) {
  60. throw new Forbidden();
  61. }
  62. public function createDirectory($name) {
  63. throw new Forbidden();
  64. }
  65. }