AbstractTrash.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 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 OCA\Files_Trashbin\Sabre;
  25. use OCA\Files_Trashbin\Trash\ITrashItem;
  26. use OCA\Files_Trashbin\Trash\ITrashManager;
  27. use OCP\Files\FileInfo;
  28. abstract class AbstractTrash implements ITrash {
  29. /** @var ITrashItem */
  30. protected $data;
  31. /** @var ITrashManager */
  32. protected $trashManager;
  33. public function __construct(ITrashManager $trashManager, ITrashItem $data) {
  34. $this->trashManager = $trashManager;
  35. $this->data = $data;
  36. }
  37. public function getFilename(): string {
  38. return $this->data->getName();
  39. }
  40. public function getDeletionTime(): int {
  41. return $this->data->getDeletedTime();
  42. }
  43. public function getFileId(): int {
  44. return $this->data->getId();
  45. }
  46. public function getFileInfo(): FileInfo {
  47. return $this->data;
  48. }
  49. public function getSize(): int {
  50. return $this->data->getSize();
  51. }
  52. public function getLastModified(): int {
  53. return $this->data->getMtime();
  54. }
  55. public function getContentType(): string {
  56. return $this->data->getMimetype();
  57. }
  58. public function getETag(): string {
  59. return $this->data->getEtag();
  60. }
  61. public function getName(): string {
  62. return $this->data->getName();
  63. }
  64. public function getOriginalLocation(): string {
  65. return $this->data->getOriginalLocation();
  66. }
  67. public function getTitle(): string {
  68. return $this->data->getTitle();
  69. }
  70. public function delete() {
  71. $this->trashManager->removeItem($this->data);
  72. }
  73. public function restore(): bool {
  74. $this->trashManager->restoreItem($this->data);
  75. return true;
  76. }
  77. }