1<?php
2
3/*
4 * vim:set softtabstop=4 shiftwidth=4 expandtab:
5 *
6 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
7 * Copyright 2001 - 2020 Ampache.org
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
21 *
22 */
23
24
25declare(strict_types=0);
26
27namespace Ampache\Module\WebDav;
28
29use Ampache\Config\ConfigContainerInterface;
30
31final class WebDavApplication
32{
33    private ConfigContainerInterface $configContainer;
34
35    private WebDavFactoryInterface $webDavFactory;
36
37    public function __construct(
38        ConfigContainerInterface $configContainer,
39        WebDavFactoryInterface $webDavFactory
40    ) {
41        $this->configContainer = $configContainer;
42        $this->webDavFactory   = $webDavFactory;
43    }
44
45    public function run(): void
46    {
47        if ($this->configContainer->isWebDavBackendEnabled() === false) {
48            echo T_('Disabled');
49
50            return;
51        }
52
53        $server = $this->webDavFactory->createServer(
54            $this->webDavFactory->createWebDavCatalog()
55        );
56
57        $raw_web_path = $this->configContainer->getRawWebPath();
58        if ($raw_web_path === '/') {
59            $raw_web_path = '';
60        }
61
62        $server->setBaseUri(
63            sprintf('%s/webdav/index.php', $raw_web_path)
64        );
65
66        if ($this->configContainer->isAuthenticationEnabled()) {
67            $server->addPlugin(
68                $this->webDavFactory->createPlugin(
69                    $this->webDavFactory->createWebDavAuth()
70                )
71            );
72        }
73
74        $server->exec();
75    }
76}
77