-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
47 lines (37 loc) · 1.08 KB
/
index.php
File metadata and controls
47 lines (37 loc) · 1.08 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
37
38
39
40
41
42
43
44
45
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Google\Protobuf\GPBEmpty;
use Grpc\ChannelCredentials;
use Todo\Task;
use Todo\TaskList;
use Todo\TasksClient;
use Todo\Text;
$client = new TasksClient('localhost:8888', [
'credentials' => ChannelCredentials::createInsecure(),
]);
$new = $_GET['task'] ?? $argv[1] ?? null;
if (null !== $new) {
/** @var Task $task */
[$task, $status] = $client->Add((new Text())->setText($new))->wait();
if ($status->code !== Grpc\STATUS_OK) {
echo "Call did not complete successfully. Status object:\n";
exit(1);
}
echo "Added task: " . $task->getText();
} else {
/** @var TaskList $reply */
[$reply, $status] = $client->List(new GPBEmpty())->wait();
if ($status->code !== Grpc\STATUS_OK) {
echo "Call did not complete successfully. Status object:\n";
exit(1);
}
/** @var Task $task */
foreach ($reply->getTasks() as $task) {
if ($task->getDone()) {
echo "✅";
} else {
echo "❌";
}
echo $task->getText() . " \n";
}
}