1
0

ServerFactory.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Direct;
  8. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  9. use OCA\DAV\Db\DirectMapper;
  10. use OCP\AppFramework\Utility\ITimeFactory;
  11. use OCP\EventDispatcher\IEventDispatcher;
  12. use OCP\Files\IRootFolder;
  13. use OCP\IConfig;
  14. use OCP\IL10N;
  15. use OCP\IRequest;
  16. use OCP\L10N\IFactory;
  17. use OCP\Security\Bruteforce\IThrottler;
  18. class ServerFactory {
  19. /** @var IL10N */
  20. private $l10n;
  21. public function __construct(
  22. private IConfig $config,
  23. IFactory $l10nFactory,
  24. private IEventDispatcher $eventDispatcher,
  25. ) {
  26. $this->l10n = $l10nFactory->get('dav');
  27. }
  28. public function createServer(string $baseURI,
  29. string $requestURI,
  30. IRootFolder $rootFolder,
  31. DirectMapper $mapper,
  32. ITimeFactory $timeFactory,
  33. IThrottler $throttler,
  34. IRequest $request): Server {
  35. $home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request, $this->eventDispatcher);
  36. $server = new Server($home);
  37. $server->httpRequest->setUrl($requestURI);
  38. $server->setBaseUri($baseURI);
  39. $server->addPlugin(new MaintenancePlugin($this->config, $this->l10n));
  40. return $server;
  41. }
  42. }