Skip to content

Commit

Permalink
Issue CollaboraOnline#56: Throw exception directly from getWopiSrcUrl().
Browse files Browse the repository at this point in the history
  • Loading branch information
donquixote committed Nov 12, 2024
1 parent 7c765ce commit b9953c1
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/Cool/CoolRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ public function getWopiClientURL(): string {
}

$wopi_src = $this->getWopiSrcUrl($discovery_parsed, 'text/plain');
if ($wopi_src === NULL) {
throw new CoolRequestException(
'The requested mime type is not handled.',
103,
);
}

return $wopi_src;
}
Expand Down Expand Up @@ -167,16 +161,21 @@ protected function getDiscovery(): string {
* @param string $mimetype
* MIME type for which to fetch the WOPI url. E.g. 'text/plain'.
*
* @return string|null
* WOPI url as configured for this MIME type in discovery.xml, or NULL if
* none was found for the given MIME type.
* @return string
* WOPI url as configured for this MIME type in discovery.xml.
*
* @throws \Drupal\collabora_online\Exception\CoolRequestException
* No WOPI url was found for this MIME type.
*/
protected function getWopiSrcUrl(\SimpleXMLElement $discovery_parsed, string $mimetype): string|null {
protected function getWopiSrcUrl(\SimpleXMLElement $discovery_parsed, string $mimetype): string {
$result = $discovery_parsed->xpath(sprintf('/wopi-discovery/net-zone/app[@name=\'%s\']/action', $mimetype));
if (!empty($result[0]['urlsrc'][0])) {
return (string) $result[0]['urlsrc'][0];
}
return NULL;
throw new CoolRequestException(
'The requested mime type is not handled.',
103,
);
}

}

0 comments on commit b9953c1

Please sign in to comment.