StorageModifierTrait.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\IStorage;
  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. * @throws InsufficientDataForMeaningfulAnswerException
  40. * @throws StorageNotAvailableException
  41. */
  42. public function wrapStorage(IStorage $storage): IStorage {
  43. return $storage;
  44. }
  45. }