Skip to content

Commit 0df0857

Browse files
committed
feat: GET, POST args can read
1 parent c764b7b commit 0df0857

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

example/get.test.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,18 @@
3636
}
3737
});
3838

39+
// Request : http://localhost:3000/test/get.test.php/argument?a=1
40+
// body : json {"b":2}
41+
// Result : 3
42+
$app->get('/argument', function ($req, $res) {
43+
try {
44+
$result = $req["a"] + $req["b"];
45+
$res->send($result);
46+
} catch (Exception $e) {
47+
http_response_code(500);
48+
return $e;
49+
}
50+
});
51+
3952
// 404 return
4053
$app->listen();

lib/phpExpress.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function __construct()
2929

3030
//Get Json data
3131
$this->req = json_decode(file_get_contents('php://input'), true);
32+
//GET data
33+
$this->req = array_merge((array) $_GET, (array) $this->req);
34+
//POST data
35+
$this->req = array_merge((array) $_POST, (array) $this->req);
3236
}
3337

3438
public static function send($result, $cache = false)
@@ -71,7 +75,8 @@ public function listen()
7175
*/
7276
private function removePhpUrl($url)
7377
{
74-
return substr($url, strpos($url, ".php") + 4);
78+
$result = substr($url, strpos($url, ".php") + 4);
79+
return substr($result, 0, strpos($result, "?"));
7580
}
7681

7782
/*

0 commit comments

Comments
 (0)