midorikocak /
nano
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | use midorikocak\nano\Api; |
||||||
| 6 | |||||||
| 7 | require __DIR__ . '/vendor/autoload.php'; |
||||||
| 8 | |||||||
| 9 | $api = new Api(); |
||||||
| 10 | |||||||
| 11 | |||||||
| 12 | $message = 'Welcome to Nano'; |
||||||
| 13 | |||||||
| 14 | $api->get('/', function () use ($message) { |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 15 | echo json_encode(['message' => $message], JSON_THROW_ON_ERROR, 512); |
||||||
| 16 | http_response_code(200); |
||||||
| 17 | }); |
||||||
| 18 | |||||||
| 19 | $api->post('/', function () use ($message) { |
||||||
|
0 ignored issues
–
show
The method
post() does not exist on midorikocak\nano\Api. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 20 | $input = (array)json_decode(file_get_contents('php://input'), true, 512, JSON_THROW_ON_ERROR); |
||||||
| 21 | echo json_encode($input, JSON_THROW_ON_ERROR, 512); |
||||||
| 22 | http_response_code(201); |
||||||
| 23 | }); |
||||||
| 24 | |||||||
| 25 | $api->get('/echo/{$message}', function ($message) { |
||||||
| 26 | echo json_encode(['message' => $message], JSON_THROW_ON_ERROR, 512); |
||||||
| 27 | http_response_code(200); |
||||||
| 28 | }); |
||||||
| 29 | |||||||
| 30 | |||||||
| 31 | $authFunction = function ($username, $password) { |
||||||
| 32 | return ($username == 'username' && $password == 'password'); |
||||||
| 33 | }; |
||||||
| 34 | |||||||
| 35 | $api->auth(function () use (&$api) { |
||||||
| 36 | |||||||
| 37 | $api->get('/entries/{id}', function ($id) { |
||||||
| 38 | echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512); |
||||||
| 39 | http_response_code(201); |
||||||
| 40 | }); |
||||||
| 41 | |||||||
| 42 | |||||||
| 43 | $api->post('/entries/{id}', function ($id) { |
||||||
| 44 | echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512); |
||||||
| 45 | http_response_code(201); |
||||||
| 46 | }); |
||||||
| 47 | |||||||
| 48 | $api->put('/entries/{id}', function ($id) { |
||||||
| 49 | echo json_encode(['id' => $id], JSON_THROW_ON_ERROR, 512); |
||||||
| 50 | http_response_code(204); |
||||||
| 51 | }); |
||||||
| 52 | |||||||
| 53 | $api->delete('/entries/{id}', function ($id) { |
||||||
| 54 | http_response_code(204); |
||||||
| 55 | }); |
||||||
| 56 | |||||||
| 57 | }, $authFunction); |
||||||
| 58 |