LegacyDependencyCheckPolyfill.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /**
  10. * Polyfill for checking dependencies using legacy Storage::checkDependencies()
  11. */
  12. trait LegacyDependencyCheckPolyfill {
  13. /**
  14. * @return class-string<IStorage>
  15. */
  16. abstract public function getStorageClass();
  17. /**
  18. * Check if object is valid for use
  19. *
  20. * @return MissingDependency[] Unsatisfied dependencies
  21. */
  22. public function checkDependencies() {
  23. $ret = [];
  24. $result = call_user_func([$this->getStorageClass(), 'checkDependencies']);
  25. if ($result !== true) {
  26. if (!is_array($result)) {
  27. $result = [$result];
  28. }
  29. foreach ($result as $key => $value) {
  30. if (!($value instanceof MissingDependency)) {
  31. $module = null;
  32. $message = null;
  33. if (is_numeric($key)) {
  34. $module = $value;
  35. } else {
  36. $module = $key;
  37. $message = $value;
  38. }
  39. $value = new MissingDependency($module);
  40. $value->setMessage($message);
  41. }
  42. $ret[] = $value;
  43. }
  44. }
  45. return $ret;
  46. }
  47. }