LegacyBackend.php 3.0 KB

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