daniel-samson / teensyphp

最简约的Web框架


README

Teensy PHP 是一个用于快速创建REST API和超媒体的微型Web框架。

项目状态

Build codecov CodeFactor

特性

  • 轻量级框架
  • 简单路由器
  • PHP模板引擎
  • 中间件支持
  • 易于注入或替换功能(只是一些小函数)

示例

// index.php
<?php
require_once __DIR__ . '/vendor/autoload.php';

router(function() {
    // uncomment when using laravel valet/herd or when mod_rewrite is unavailable:
    // use_request_uri();
    //
    // healthcheck
    route(method(GET), url_path("/"), fn () => render(200, json_out(['status' => 'up'])));
    
    // Example url parameter
    route(method(GET), url_path_params("/hello/:name"), function () {
        render(200, html_out(template('src/templates/hello.php', ['name' => $_GET[':name']])));
    });
    
    // Example JSON body (echo server)
    route(method(POST), url_path("/echo"), function () {
        $body = json_in();
        render(201, json_out($body));
    });
});

要求

  • PHP 7.2+
  • Composer

文档

请参阅wiki以获取有关如何使用Teensy PHP快速创建应用程序的更多信息。