-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathworker.php
57 lines (47 loc) · 1.5 KB
/
worker.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
51
52
53
54
55
56
57
<?php
error_reporting(E_ERROR | E_PARSE);
class Logger {
public $messages = [];
function information(string $msg) {
array_push($this->messages, $msg);
}
}
class FunctionContext {
public $inputs = [];
public $outputs;
public $log;
public function __construct() {
$this->log = new Logger();
$this->outputs = [ '_none_' => null ];
}
}
$context = new FunctionContext();
set_exception_handler(function ($exception) use ($context) {
$context->log->information($exception);
$response = [
'Outputs' => NULL,
'ReturnValue' => NULL,
'Logs' => $context->log->messages
];
echo(json_encode($response));
});
$requestUri = $_SERVER['REQUEST_URI'];
$requestBody = file_get_contents('php://input');
// $context->log->information($requestBody);
// $context->log->information('headers: ' . json_encode(getallheaders()));
$request = json_decode($requestBody, true);
header("Content-type: application/json");
require __DIR__ . $requestUri . '/index.php';
$context->inputs = $request['Data'];
$returnValue = run($context);
if (is_null($returnValue)) {
$returnValue = "";
}
$response = [
'Outputs' => $context->outputs,
'ReturnValue' => $returnValue,
'Logs' => $context->log->messages
];
header("Content-type: application/json");
echo(json_encode($response));
?>