LegacyBackend.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\Backend;
  8. use OCA\Files_External\Lib\Auth\Builtin;
  9. use OCA\Files_External\Lib\DefinitionParameter;
  10. use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
  11. use OCA\Files_External\Lib\MissingDependency;
  12. /**
  13. * Legacy compatibility for OCA\Files_External\MountConfig::registerBackend()
  14. */
  15. class LegacyBackend extends Backend {
  16. use LegacyDependencyCheckPolyfill {
  17. LegacyDependencyCheckPolyfill::checkDependencies as doCheckDependencies;
  18. }
  19. /** @var bool */
  20. protected $hasDependencies = false;
  21. /**
  22. * @param string $class
  23. * @param array $definition
  24. * @param Builtin $authMechanism
  25. */
  26. public function __construct($class, array $definition, Builtin $authMechanism) {
  27. $this
  28. ->setIdentifier($class)
  29. ->setStorageClass($class)
  30. ->setText($definition['backend'])
  31. ->addAuthScheme(Builtin::SCHEME_BUILTIN)
  32. ->setLegacyAuthMechanism($authMechanism)
  33. ;
  34. foreach ($definition['configuration'] as $name => $placeholder) {
  35. $flags = DefinitionParameter::FLAG_NONE;
  36. $type = DefinitionParameter::VALUE_TEXT;
  37. if ($placeholder[0] === '&') {
  38. $flags = DefinitionParameter::FLAG_OPTIONAL;
  39. $placeholder = substr($placeholder, 1);
  40. }
  41. switch ($placeholder[0]) {
  42. case '!':
  43. $type = DefinitionParameter::VALUE_BOOLEAN;
  44. $placeholder = substr($placeholder, 1);
  45. break;
  46. case '*':
  47. $type = DefinitionParameter::VALUE_PASSWORD;
  48. $placeholder = substr($placeholder, 1);
  49. break;
  50. case '#':
  51. $type = DefinitionParameter::VALUE_HIDDEN;
  52. $placeholder = substr($placeholder, 1);
  53. break;
  54. }
  55. $this->addParameter((new DefinitionParameter($name, $placeholder))
  56. ->setType($type)
  57. ->setFlags($flags)
  58. );
  59. }
  60. if (isset($definition['priority'])) {
  61. $this->setPriority($definition['priority']);
  62. }
  63. if (isset($definition['custom'])) {
  64. $this->addCustomJs($definition['custom']);
  65. }
  66. if (isset($definition['has_dependencies']) && $definition['has_dependencies']) {
  67. $this->hasDependencies = true;
  68. }
  69. }
  70. /**
  71. * @return MissingDependency[]
  72. */
  73. public function checkDependencies() {
  74. if ($this->hasDependencies) {
  75. return $this->doCheckDependencies();
  76. }
  77. return [];
  78. }
  79. }