Skip to content

Commit 2916381

Browse files
committed
fix: url parm bug fix
1 parent aaaee8a commit 2916381

2 files changed

Lines changed: 59 additions & 12 deletions

File tree

example/retrun.test.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* If you read that data from a web browser,
88
*/
99

10-
// Request : http://localhost:3000/example/retrun.test.php/get
11-
// Result :
12-
$app->get('/get', function ($req, $res) {
10+
// Request : http://localhost:3000/example/retrun.test.php/
11+
// Result : {"msg":"phpExpress"}
12+
$app->get('/', function ($req, $res) {
1313
try {
1414
$res->send((object) ["msg" => "phpExpress"]);
1515
} catch (Exception $e) {
@@ -18,9 +18,53 @@
1818
}
1919
});
2020

21-
// Request : http://localhost:3000/example/retrun.test.php/post
21+
// Request : http://localhost:3000/example/retrun.test.php/
2222
// Result : {"msg": "phpExpress"}
23-
$app->post('/post', function ($req, $res) {
23+
$app->post('/', function ($req, $res) {
24+
try {
25+
$res->send((object) ["msg" => "phpExpress"]);
26+
} catch (Exception $e) {
27+
http_response_code(500);
28+
$res->send($e);
29+
}
30+
});
31+
32+
// Request : http://localhost:3000/example/retrun.test.php/
33+
// Result : {"msg": "phpExpress"}
34+
$app->put('/', function ($req, $res) {
35+
try {
36+
$res->send((object) ["msg" => "phpExpress"]);
37+
} catch (Exception $e) {
38+
http_response_code(500);
39+
$res->send($e);
40+
}
41+
});
42+
43+
// Request : http://localhost:3000/example/retrun.test.php/
44+
// Result : {"msg": "phpExpress"}
45+
$app->patch('/', function ($req, $res) {
46+
try {
47+
$res->send((object) ["msg" => "phpExpress"]);
48+
} catch (Exception $e) {
49+
http_response_code(500);
50+
$res->send($e);
51+
}
52+
});
53+
54+
// Request : http://localhost:3000/example/retrun.test.php/
55+
// Result : {"msg": "phpExpress"}
56+
$app->delete('/', function ($req, $res) {
57+
try {
58+
$res->send((object) ["msg" => "phpExpress"]);
59+
} catch (Exception $e) {
60+
http_response_code(500);
61+
$res->send($e);
62+
}
63+
});
64+
65+
// Request : http://localhost:3000/example/retrun.test.php/
66+
// Result : {"msg": "phpExpress"}
67+
$app->options('/', function ($req, $res) {
2468
try {
2569
$res->send((object) ["msg" => "phpExpress"]);
2670
} catch (Exception $e) {

lib/phpExpress.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ private function convertParm($parm)
114114
public function get($parm, $function)
115115
{
116116
$parm = $this->convertParm($parm);
117-
// echo $this->removePhpUrl($_SERVER['REQUEST_URI']) . "===" . $parm . "<br/>";
118-
119117
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
120118
return;
121119
} else if (strcmp($this->removePhpUrl($_SERVER['REQUEST_URI']), $parm)) {
@@ -128,57 +126,62 @@ public function get($parm, $function)
128126

129127
public function post($parm, $function)
130128
{
129+
$parm = $this->convertParm($parm);
131130
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
132131
return;
133132
} else if (strcmp($this->removePhpUrl($_SERVER['REQUEST_URI']), $parm)) {
134133
return;
135134
}
136135

137136
http_response_code(201);
138-
$this->send($function($this->req));
137+
$function($this->req, $this);
139138
}
140139

141140
public function put($parm, $function)
142141
{
142+
$parm = $this->convertParm($parm);
143143
if ($_SERVER['REQUEST_METHOD'] !== 'PUT') {
144144
return;
145145
} else if (strcmp($this->removePhpUrl($_SERVER['REQUEST_URI']), $parm)) {
146146
return;
147147
}
148148

149-
$this->send($function($this->req));
149+
$function($this->req, $this);
150150
}
151151

152152
public function patch($parm, $function)
153153
{
154+
$parm = $this->convertParm($parm);
154155
if ($_SERVER['REQUEST_METHOD'] !== 'PATCH') {
155156
return;
156157
} else if (strcmp($this->removePhpUrl($_SERVER['REQUEST_URI']), $parm)) {
157158
return;
158159
}
159160

160-
$this->send($function($this->req));
161+
$function($this->req, $this);
161162
}
162163

163164
public function delete($parm, $function)
164165
{
166+
$parm = $this->convertParm($parm);
165167
if ($_SERVER['REQUEST_METHOD'] !== 'DELETE') {
166168
return;
167169
} else if (strcmp($this->removePhpUrl($_SERVER['REQUEST_URI']), $parm)) {
168170
return;
169171
}
170172

171-
$this->send($function($this->req));
173+
$function($this->req, $this);
172174
}
173175

174176
public function options($parm, $function)
175177
{
178+
$parm = $this->convertParm($parm);
176179
if ($_SERVER['REQUEST_METHOD'] !== 'OPTIONS') {
177180
return;
178181
} else if (strcmp($this->removePhpUrl($_SERVER['REQUEST_URI']), $parm)) {
179182
return;
180183
}
181184

182-
$this->send($function($this->req));
185+
$function($this->req, $this);
183186
}
184187
}

0 commit comments

Comments
 (0)