generated from Nodarx/template
Add WOPI discovery service and connection diagnostics
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ServiceWopi\Discovery;
|
||||
|
||||
final readonly class Action
|
||||
{
|
||||
/** @param list<string> $requirements */
|
||||
public function __construct(
|
||||
public string $extension,
|
||||
public string $name,
|
||||
public string $url,
|
||||
public array $requirements,
|
||||
) {}
|
||||
|
||||
/** @param list<string> $capabilities */
|
||||
public function supportedBy(array $capabilities): bool
|
||||
{
|
||||
$required = $this->requirements;
|
||||
if (in_array($this->name, ['edit', 'editnew', 'convert'], true)) {
|
||||
$required = array_merge($required, ['locks', 'update']);
|
||||
}
|
||||
return array_diff($required, $capabilities) === [];
|
||||
}
|
||||
|
||||
public function launchUrl(string $wopiSource): string
|
||||
{
|
||||
new ServerAddress($wopiSource);
|
||||
$url = preg_replace_callback('/<([^=<>]+)=([^<>]*?)(\&?)>/',
|
||||
static fn (array $match): string => $match[2] === 'WOPI_SOURCE'
|
||||
? $match[1] . '=' . rawurlencode($wopiSource) . $match[3] : '',
|
||||
$this->url,
|
||||
);
|
||||
$query = parse_url($url, PHP_URL_QUERY) ?? '';
|
||||
if (!preg_match('/(?:^|&)WOPISrc=/i', $query)) {
|
||||
$url = rtrim($url, '?&');
|
||||
$url .= (str_contains($url, '?') ? '&' : '?') . 'WOPISrc=' . rawurlencode($wopiSource);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user