ServerFactory.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 IConfig */
  20. private $config;
  21. /** @var IL10N */
  22. private $l10n;
  23. /** @var IEventDispatcher */
  24. private $eventDispatcher;
  25. public function __construct(IConfig $config, IFactory $l10nFactory, IEventDispatcher $eventDispatcher) {
  26. $this->config = $config;
  27. $this->l10n = $l10nFactory->get('dav');
  28. $this->eventDispatcher = $eventDispatcher;
  29. }
  30. public function createServer(string $baseURI,
  31. string $requestURI,
  32. IRootFolder $rootFolder,
  33. DirectMapper $mapper,
  34. ITimeFactory $timeFactory,
  35. IThrottler $throttler,
  36. IRequest $request): Server {
  37. $home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request, $this->eventDispatcher);
  38. $server = new Server($home);
  39. $server->httpRequest->setUrl($requestURI);
  40. $server->setBaseUri($baseURI);
  41. $server->addPlugin(new MaintenancePlugin($this->config, $this->l10n));
  42. return $server;
  43. }
  44. }