-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginDefinitionScanner.php
More file actions
36 lines (30 loc) · 1.19 KB
/
PluginDefinitionScanner.php
File metadata and controls
36 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare(strict_types=1);
namespace Gared\EtherScan\Service\Scanner;
use Gared\EtherScan\Exception\EtherpadServiceNotFoundException;
use Gared\EtherScan\Service\ScannerServiceCallbackInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use JsonException;
readonly class PluginDefinitionScanner
{
public function scan(Client $client, string $baseUrl, ScannerServiceCallbackInterface $callback): void
{
try {
$response = $client->get($baseUrl . 'pluginfw/plugin-definitions.json');
try {
$body = (string)$response->getBody();
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
if (is_array($data) === false || array_key_exists('plugins', $data) === false) {
throw new EtherpadServiceNotFoundException('No Etherpad service found');
}
$onlyPlugins = $data['plugins'];
$callback->onScanPluginsList($onlyPlugins);
} catch (JsonException $e) {
$callback->onScanApiException($e);
}
} catch (GuzzleException $e) {
$callback->onScanApiException($e);
}
}
}