legacybackend.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @author Robin McCorkell <robin@mccorkell.me.uk>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\Files_External\Lib\Backend;
  22. use \OCA\Files_External\Lib\DefinitionParameter;
  23. use \OCA\Files_External\Lib\Backend\Backend;
  24. use \OCA\Files_External\Lib\Auth\Builtin;
  25. use \OCA\Files_External\Lib\MissingDependency;
  26. use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
  27. /**
  28. * Legacy compatibility for OC_Mount_Config::registerBackend()
  29. */
  30. class LegacyBackend extends Backend {
  31. use LegacyDependencyCheckPolyfill {
  32. LegacyDependencyCheckPolyfill::checkDependencies as doCheckDependencies;
  33. }
  34. /** @var bool */
  35. protected $hasDependencies = false;
  36. /**
  37. * @param string $class
  38. * @param array $definition
  39. * @param Builtin $authMechanism
  40. */
  41. public function __construct($class, array $definition, Builtin $authMechanism) {
  42. $this
  43. ->setIdentifier($class)
  44. ->setStorageClass($class)
  45. ->setText($definition['backend'])
  46. ->addAuthScheme(Builtin::SCHEME_BUILTIN)
  47. ->setLegacyAuthMechanism($authMechanism)
  48. ;
  49. foreach ($definition['configuration'] as $name => $placeholder) {
  50. $flags = DefinitionParameter::FLAG_NONE;
  51. $type = DefinitionParameter::VALUE_TEXT;
  52. if ($placeholder[0] === '&') {
  53. $flags = DefinitionParameter::FLAG_OPTIONAL;
  54. $placeholder = substr($placeholder, 1);
  55. }
  56. switch ($placeholder[0]) {
  57. case '!':
  58. $type = DefinitionParameter::VALUE_BOOLEAN;
  59. $placeholder = substr($placeholder, 1);
  60. break;
  61. case '*':
  62. $type = DefinitionParameter::VALUE_PASSWORD;
  63. $placeholder = substr($placeholder, 1);
  64. break;
  65. case '#':
  66. $type = DefinitionParameter::VALUE_HIDDEN;
  67. $placeholder = substr($placeholder, 1);
  68. break;
  69. }
  70. $this->addParameter((new DefinitionParameter($name, $placeholder))
  71. ->setType($type)
  72. ->setFlags($flags)
  73. );
  74. }
  75. if (isset($definition['priority'])) {
  76. $this->setPriority($definition['priority']);
  77. }
  78. if (isset($definition['custom'])) {
  79. $this->setCustomJs($definition['custom']);
  80. }
  81. if (isset($definition['has_dependencies']) && $definition['has_dependencies']) {
  82. $this->hasDependencies = true;
  83. }
  84. }
  85. /**
  86. * @return MissingDependency[]
  87. */
  88. public function checkDependencies() {
  89. if ($this->hasDependencies) {
  90. return $this->doCheckDependencies();
  91. }
  92. return [];
  93. }
  94. }