1
0

BeforeZipCreatedEvent.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Files\Events;
  8. use OCP\EventDispatcher\Event;
  9. use OCP\Files\Folder;
  10. /**
  11. * This event is triggered before a archive is created when a user requested
  12. * downloading a folder or multiple files.
  13. *
  14. * By setting `successful` to false the tar creation can be aborted and the download denied.
  15. *
  16. * @since 25.0.0
  17. */
  18. class BeforeZipCreatedEvent extends Event {
  19. private string $directory;
  20. private bool $successful = true;
  21. private ?string $errorMessage = null;
  22. private ?Folder $folder = null;
  23. /**
  24. * @param list<string> $files
  25. * @since 25.0.0
  26. * @since 31.0.0 support `OCP\Files\Folder` as `$directory` parameter - passing a string is deprecated now
  27. */
  28. public function __construct(
  29. string|Folder $directory,
  30. private array $files,
  31. ) {
  32. parent::__construct();
  33. if ($directory instanceof Folder) {
  34. $this->directory = $directory->getPath();
  35. $this->folder = $directory;
  36. } else {
  37. $this->directory = $directory;
  38. }
  39. }
  40. /**
  41. * @since 31.0.0
  42. */
  43. public function getFolder(): ?Folder {
  44. return $this->folder;
  45. }
  46. /**
  47. * @since 25.0.0
  48. */
  49. public function getDirectory(): string {
  50. return $this->directory;
  51. }
  52. /**
  53. * @since 25.0.0
  54. */
  55. public function getFiles(): array {
  56. return $this->files;
  57. }
  58. /**
  59. * @since 25.0.0
  60. */
  61. public function isSuccessful(): bool {
  62. return $this->successful;
  63. }
  64. /**
  65. * Set if the event was successful
  66. *
  67. * @since 25.0.0
  68. */
  69. public function setSuccessful(bool $successful): void {
  70. $this->successful = $successful;
  71. }
  72. /**
  73. * Get the error message, if any
  74. * @since 25.0.0
  75. */
  76. public function getErrorMessage(): ?string {
  77. return $this->errorMessage;
  78. }
  79. /**
  80. * @since 25.0.0
  81. */
  82. public function setErrorMessage(string $errorMessage): void {
  83. $this->errorMessage = $errorMessage;
  84. }
  85. }