-
Notifications
You must be signed in to change notification settings - Fork 2
/
client-tester.php
executable file
·50 lines (46 loc) · 1.31 KB
/
client-tester.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env php
<?php
$argv = $_SERVER['argv'];
if (2 !== count($argv)) {
error_log('Broker required');
exit(1);
}
require_once __DIR__.'/vendor/autoload.php';
$client = new \Portier\Client\Client(
new \Portier\Client\MemoryStore(),
'http://imaginary-client.test/fake-verify-route'
);
$client->broker = $argv[1];
$stdin = fopen('php://stdin', 'r');
while (($line = fgets($stdin, 4096)) !== false) {
$cmd = explode("\t", trim($line));
switch ($cmd[0]) {
case 'echo':
echo "ok\t{$cmd[1]}\n";
break;
case 'auth':
try {
$authUrl = $client->authenticate($cmd[1], $cmd[2] ?? '');
echo "ok\t{$authUrl}\n";
} catch (Throwable $err) {
$msg = implode(' ', explode("\n", $err->getMessage()));
echo "err\t{$msg}\n";
}
break;
case 'verify':
try {
$email = $client->verify($cmd[1]);
echo "ok\t{$email}\n";
} catch (Throwable $err) {
$msg = implode(' ', explode("\n", $err->getMessage()));
echo "err\t{$msg}\n";
}
break;
default:
error_log("invalid command: {$cmd[0]}");
exit(1);
}
}
if (!feof($stdin)) {
exit(1);
}