chonla/alex

A pico-sized PHP framework.

0.1.2 2018-08-16 15:34 UTC

This package is auto-updated.

Last update: 2024-05-20 16:38:30 UTC


README

A pico-sized PHP framework.

Feature

  • HTTP Router with named routes.
  • PassThrough Response - Non-cached proxy for GET requests.
  • Json Response - Return JSON response.

Example

$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();

Tests

Sorry, no tests so far.

License

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