ServerFactory.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 OC\Security\Bruteforce\Throttler;
  28. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  29. use OCA\DAV\Db\DirectMapper;
  30. use OCP\AppFramework\Utility\ITimeFactory;
  31. use OCP\EventDispatcher\IEventDispatcher;
  32. use OCP\Files\IRootFolder;
  33. use OCP\IConfig;
  34. use OCP\IL10N;
  35. use OCP\IRequest;
  36. use OCP\L10N\IFactory;
  37. class ServerFactory {
  38. /** @var IConfig */
  39. private $config;
  40. /** @var IL10N */
  41. private $l10n;
  42. private $eventDispatcher;
  43. public function __construct(IConfig $config, IFactory $l10nFactory, IEventDispatcher $eventDispatcher) {
  44. $this->config = $config;
  45. $this->l10n = $l10nFactory->get('dav');
  46. $this->eventDispatcher = $eventDispatcher;
  47. }
  48. public function createServer(string $baseURI,
  49. string $requestURI,
  50. IRootFolder $rootFolder,
  51. DirectMapper $mapper,
  52. ITimeFactory $timeFactory,
  53. Throttler $throttler,
  54. IRequest $request): Server {
  55. $home = new DirectHome($rootFolder, $mapper, $timeFactory, $throttler, $request, $this->eventDispatcher);
  56. $server = new Server($home);
  57. $server->httpRequest->setUrl($requestURI);
  58. $server->setBaseUri($baseURI);
  59. $server->addPlugin(new MaintenancePlugin($this->config, $this->l10n));
  60. return $server;
  61. }
  62. }