StorageModifierTrait.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Lib;
  8. use OCP\Files\Storage;
  9. use OCP\Files\StorageNotAvailableException;
  10. use OCP\IUser;
  11. /**
  12. * Trait for objects that can modify StorageConfigs and wrap Storages
  13. *
  14. * When a storage implementation is being prepared for use, the StorageConfig
  15. * is passed through manipulateStorageConfig() to update any parameters as
  16. * necessary. After the storage implementation has been constructed, it is
  17. * passed through wrapStorage(), potentially replacing the implementation with
  18. * a wrapped storage that changes its behaviour.
  19. *
  20. * Certain configuration options need to be set before the implementation is
  21. * constructed, while others are retrieved directly from the storage
  22. * implementation and so need a wrapper to be modified.
  23. */
  24. trait StorageModifierTrait {
  25. /**
  26. * Modify a StorageConfig parameters
  27. *
  28. * @param StorageConfig $storage
  29. * @param IUser $user User the storage is being used as
  30. * @return void
  31. * @throws InsufficientDataForMeaningfulAnswerException
  32. * @throws StorageNotAvailableException
  33. */
  34. public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user = null) {
  35. }
  36. /**
  37. * Wrap a Storage if necessary
  38. *
  39. * @param Storage $storage
  40. * @return Storage
  41. * @throws InsufficientDataForMeaningfulAnswerException
  42. * @throws StorageNotAvailableException
  43. */
  44. public function wrapStorage(Storage $storage) {
  45. return $storage;
  46. }
  47. }