Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
UrlSettings
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDefaultUrl
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getAllowedMediaHosts
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * The phpMyFAQ URL settings class
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2025-2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2025-11-03
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Configuration;
21
22use phpMyFAQ\Configuration as CoreConfiguration;
23
24readonly class UrlSettings
25{
26    public function __construct(
27        private CoreConfiguration $coreConfiguration,
28    ) {
29    }
30
31    public function getDefaultUrl(): string
32    {
33        $defaultUrl = (string) $this->coreConfiguration->get(item: 'main.referenceURL');
34        return str_ends_with($defaultUrl, '/') ? $defaultUrl : $defaultUrl . '/';
35    }
36
37    /**
38     * Returns an array with allowed media hosts for records.
39     * @return string[]
40     */
41    public function getAllowedMediaHosts(): array
42    {
43        $val = (string) $this->coreConfiguration->get(item: 'records.allowedMediaHosts');
44        return $val === '' ? [] : explode(',', $val);
45    }
46}