1
0

AbstractTrash.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /**
  50. * @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
  51. * @return int|float
  52. */
  53. public function getSize(): int|float {
  54. return $this->data->getSize();
  55. }
  56. public function getLastModified(): int {
  57. return $this->data->getMtime();
  58. }
  59. public function getContentType(): string {
  60. return $this->data->getMimetype();
  61. }
  62. public function getETag(): string {
  63. return $this->data->getEtag();
  64. }
  65. public function getName(): string {
  66. return $this->data->getName();
  67. }
  68. public function getOriginalLocation(): string {
  69. return $this->data->getOriginalLocation();
  70. }
  71. public function getTitle(): string {
  72. return $this->data->getTitle();
  73. }
  74. public function delete() {
  75. $this->trashManager->removeItem($this->data);
  76. }
  77. public function restore(): bool {
  78. $this->trashManager->restoreItem($this->data);
  79. return true;
  80. }
  81. }