generated from Nodarx/template
54 lines
2.2 KiB
PHP
54 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXM\ServiceWopi\Console;
|
|
|
|
use KTXM\ServiceWopi\Discovery\DiscoveryClient;
|
|
use KTXM\ServiceWopi\Discovery\ServerAddress;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
use Throwable;
|
|
|
|
#[AsCommand(name: 'wopi:check', description: 'Check document server discovery without sending documents or credentials')]
|
|
class CheckCommand extends Command
|
|
{
|
|
public function __construct(private readonly DiscoveryClient $client) { parent::__construct(); }
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this->addArgument('server', InputArgument::REQUIRED, 'HTTPS base URL of the document server');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
try {
|
|
$document = $this->client->fetch(new ServerAddress($input->getArgument('server')));
|
|
$rows = [];
|
|
$hasDocxView = false;
|
|
foreach ($document->actions as $action) {
|
|
$rows[] = [$action->extension, $action->name, implode(', ', $action->requirements) ?: 'none'];
|
|
$hasDocxView = $hasDocxView || ($action->extension === 'docx'
|
|
&& $action->name === 'view' && $action->supportedBy([]));
|
|
}
|
|
$io->table(['Extension', 'Server action', 'Additional host requirements'], $rows);
|
|
$io->text('Proof key metadata: ' . ($document->hasProofKeys ? 'present (not yet validated)' : 'absent'));
|
|
if (!$hasDocxView) {
|
|
$io->error('No DOCX view action usable by a basic read-only host.');
|
|
return Command::FAILURE;
|
|
}
|
|
$io->success('Discovery supports the planned DOCX viewing flow.');
|
|
$io->note('This check does not verify editor loading, WOPI callbacks, proof signatures, or saving.');
|
|
return Command::SUCCESS;
|
|
} catch (Throwable $error) {
|
|
$io->error($error->getMessage());
|
|
return Command::FAILURE;
|
|
}
|
|
}
|
|
}
|