chonla / alex

一款微型PHP框架。

0.1.2 2018-08-16 15:34 UTC

This package is auto-updated.

Last update: 2024-09-20 17:21:58 UTC


README

一款微型PHP框架。

功能

  • 带命名路由的HTTP路由器。
  • PassThrough响应 - 非缓存GET请求代理。
  • JSON响应 - 返回JSON响应。

示例

$r = new Alex\Router();
$r->get('/', 'hello');
$r->get('/aa', 'hello 2');
$r->get('/bb', 'hello 3');
$r->get('/bb/:id', function($id) {
    return new Alex\JsonResponse(200, [
        'message' => 'It works! ID is '. print_r($id, true)
    ]);
});
$r->get('/cc/test', function() {
    return new Alex\PassThroughResponse('http://www.google.com');
});
$r->post('/cc/test', function() {
    return new Alex\JsonResponse(201, (new Alex\JsonRequest())->toJson());
});
$r->put('/cc/test', function() {
    return new Alex\JsonResponse(200, (new Alex\JsonRequest())->toJson());
});
$r->delete('/cc/test', function() {
    return new Alex\JsonResponse(200, [
        'message' => 'It works! Item has gone'
    ]);
});

$r->go();

测试

抱歉,目前没有测试。

许可证

MIT: http://chonla.mit-license.org/