generated from Nodarx/template
92e85aed47
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
33 lines
1.4 KiB
PHP
33 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace KTXM\ServiceWopi\Host;
|
|
|
|
use KTXM\ServiceWopi\Discovery\ServerAddress;
|
|
|
|
final readonly class Configuration
|
|
{
|
|
public ServerAddress $office;
|
|
public ServerAddress $origin;
|
|
public int $lifetime;
|
|
public int $maxBytes;
|
|
|
|
public function __construct(array $settings, array $domains = [])
|
|
{
|
|
if (($settings['enabled'] ?? false) !== true) {
|
|
throw new HostException('Office viewing is not configured.', 503);
|
|
}
|
|
try {
|
|
$this->office = new ServerAddress($settings['office_server'] ?? '');
|
|
$this->origin = new ServerAddress($settings['origin_server'] ?? (count(array_unique($domains)) === 1 ? 'https://' . reset($domains) : ''));
|
|
} catch (\InvalidArgumentException|\TypeError $error) {
|
|
throw new HostException('Office viewing requires valid HTTPS server and application URLs.', 503);
|
|
}
|
|
// WOPI routes are mounted under /m/service_wopi, so the origin must be a bare HTTPS origin the route path can be appended to.
|
|
if ($this->origin->url !== $this->origin->origin) {
|
|
throw new HostException('The WOPI origin server URL must be an HTTPS origin without a path.', 503);
|
|
}
|
|
$this->lifetime = max(300, min(14400, (int) ($settings['token_lifetime'] ?? 3600)));
|
|
$this->maxBytes = max(1, min(32 * 1024 * 1024, (int) ($settings['max_bytes'] ?? 16 * 1024 * 1024)));
|
|
}
|
|
}
|