jasonmichels/lift-framework

Lift 是一个用于构建微服务的 PHP 7 微型框架

0.0.1 2016-06-07 15:18 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:53:12 UTC


README

Lift - PHP 7 微型框架

介绍

Lift 是一个有观点的 PHP 7 微型框架

示例

declare(strict_types=1);
require('../vendor/autoload.php');

use Lift\Framework\App;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Lift\Framework\Http\Response;

function getHomepage(Request $request): JsonResponse {
    $response = Response\json();
    $response->setData(['data' => ['stuff' => 'is awesome']]);
    return $response;
}

function getUserHandler (Request $request, array $args): JsonResponse {
    $response = Response\json();
    $response->setData(['data' => ['userId' => $args['id'], 'username' => 'Jason Michels']]);
    return $response;
}

$app = new App();

$routes = [
    ['httpMethod' => Request::METHOD_GET, 'route' => '/', 'handler' => 'getHomepage'],
    ['httpMethod' => Request::METHOD_GET, 'route' => '/user/{id:\d+}', 'handler' => 'getUserHandler']
];

$app->run($routes);

测试

$ phpunit
  • 做得更好!

语言

  • PHP 7

许可证

GroundworkPHP 是开源软件,许可协议为 MIT 许可协议

作者

  • Jason Michels