ServerFactory.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\Direct;
  27. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  28. use OCA\DAV\Db\DirectMapper;
  29. use OCP\AppFramework\Utility\ITimeFactory;
  30. use OCP\EventDispatcher\IEventDispatcher;
  31. use OCP\Files\IRootFolder;
  32. use OCP\IConfig;
  33. use OCP\IL10N;
  34. use OCP\IRequest;
  35. use OCP\L10N\IFactory;
  36. use OCP\Security\Bruteforce\IThrottler;
  37. class ServerFactory {
  38. /** @var IConfig */
  39. private $config;
  40. /** @var IL10N */
  41. private $l10n;
  42. /** @var IEventDispatcher */
  43. private $eventDispatcher;
  44. public function __construct(IConfig $config, IFactory $l10nFactory, IEventDispatcher $eventDispatcher) {
  45. $this->config = $config;
  46. $this->l10n = $l10nFactory->get('dav');
  47. $this->eventDispatcher = $eventDispatcher;
  48. }
  49. public function createServer(string $baseURI,
  50. string $requestURI,
  51. IRootFolder $rootFolder,
  52. DirectMapper $mapper,
  53. ITimeFactory $timeFactory,
  54. IThrottler $throttler,
  55. IRequest $request): Server {
  56. $home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request, $this->eventDispatcher);
  57. $server = new Server($home);
  58. $server->httpRequest->setUrl($requestURI);
  59. $server->setBaseUri($baseURI);
  60. $server->addPlugin(new MaintenancePlugin($this->config, $this->l10n));
  61. return $server;
  62. }
  63. }