Skip to content

Commit b09dd0c

Browse files
authored
Add callback for pad title (#174)
* Add callback for pad title * Adapt output in tests * Check title exists
1 parent 1807899 commit b09dd0c

5 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/Console/ScanCommandOutputHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public function onScanPadException(Throwable $e): void
138138
$this->symfonyStyle->error($e->getMessage());
139139
}
140140

141+
public function onScanPadTitle(string $title): void
142+
{
143+
$this->symfonyStyle->info('Title: ' . $title);
144+
}
145+
141146
public function onScanPadSuccess(): void
142147
{
143148
$this->symfonyStyle->success('Pads are publicly accessible');

src/Service/Scanner/PadSocketIoScanner.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ public function scan(Config $config, VersionRangeService $versionRangeService, S
2828
$callback->onScanPadStart();
2929
$cookies = new CookieJar();
3030
try {
31-
$this->client->get($config->baseUrl . $config->pathPrefix . $config->padId, [
31+
$response = $this->client->get($config->baseUrl . $config->pathPrefix . $config->padId, [
3232
'cookies' => $cookies,
3333
'timeout' => $config->timeout,
3434
]);
35+
36+
$body = (string) $response->getBody();
37+
$result = preg_match('/<title[^>]*>(?<title>.*?)<\/title>/i', $body, $matches);
38+
if ($result !== false && isset($matches['title'])) {
39+
$callback->onScanPadTitle($matches['title']);
40+
}
3541
} catch (GuzzleException $e) {
3642
$callback->onScanPadException($e);
3743
}

src/Service/ScannerServiceCallbackInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function onScanPadStart(): void;
5555

5656
public function onScanPadException(Throwable $e): void;
5757

58+
public function onScanPadTitle(string $title): void;
59+
5860
public function onScanPadSuccess(): void;
5961

6062
public function onConnectedTransport(bool $usedWebsocket): void;

tests/e2e/fixture/latest.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Starting scan of api: http://localhost:9001/
99
Starting scan of a pad...
1010
=========================
1111

12+
[INFO] Title: Etherpad
13+
1214
[OK] Websocket is supported
1315

1416
[INFO] Package version: $EP_VERSION

tests/e2e/fixture/master_with_plugins.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Starting scan of api: http://localhost:9001/
99
Starting scan of a pad...
1010
=========================
1111

12+
[INFO] Title: Etherpad
13+
1214
[OK] Websocket is supported
1315

1416

0 commit comments

Comments
 (0)