This commit is contained in:
2020-02-01 16:47:12 +07:00
commit 4c619ad6e6
16739 changed files with 3329179 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
hhvm.server.port = 8010
hhvm.server.type = proxygen
hhvm.server.default_document = index.php
hhvm.server.error_document404 = index.php
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
hhvm.log.use_log_file = false
hhvm.hack.lang.auto_typecheck=0
hhvm.hack.lang.look_for_typechecker=0

View File

@@ -0,0 +1,65 @@
<?php
include_once 'server.php';
$GLOBALS['RESTmap'] = [];
$GLOBALS['RESTmap']['GET'] = [
'user' => function() {
return [
'name' => 'davert',
'email' => 'davert@mail.ua',
'aliases' => [
'DavertMik',
'davert.ua'
],
'address' => [
'city' => 'Kyiv',
'country' => 'Ukraine',
]];
},
'zeroes' => function() {
return [
'responseCode' => 0,
'message' => 'OK',
'data' => [
9,
0,
0
],
];
},
'http-host' => function() {
return 'host: "' . $_SERVER['HTTP_HOST'] . '"';
}
];
$GLOBALS['RESTmap']['POST'] = [
'user' => function() {
$name = $_POST['name'];
return ['name' => $name];
},
'file-upload' => function() {
return [
'uploaded' => isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name']),
];
}
];
$GLOBALS['RESTmap']['PUT'] = [
'user' => function() {
$name = $_REQUEST['name'];
$user = ['name' => 'davert', 'email' => 'davert@mail.ua'];
$user['name'] = $name;
return $user;
}
];
$GLOBALS['RESTmap']['DELETE'] = [
'user' => function() {
header('error', false, 404);
}
];
RESTServer();

View File

@@ -0,0 +1,30 @@
<?php
function RESTServer()
{
// find the function/method to call
$callback = NULL;
if (preg_match('/rest\/([^\/]+)/i', $_SERVER['REQUEST_URI'], $m)) {
if (isset($GLOBALS['RESTmap'][$_SERVER['REQUEST_METHOD']][$m[1]])) {
$callback = $GLOBALS['RESTmap'][$_SERVER['REQUEST_METHOD']][$m[1]];
}
}
if ($callback) {
// get the request data
$data = NULL;
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$data = $_GET;
} else if ($tmp = file_get_contents('php://input')) {
$data = json_decode($tmp);
}
$response = call_user_func($callback, $data);
if (is_scalar($response)) {
print $response;
return;
}
print json_encode($response);
}
}