定制 malinichevvv/lift-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

malinichevvv/lift-php

最新稳定版本:v1.4.0

Composer 安装命令:

composer require malinichevvv/lift-php

包简介

A fast, minimal PHP micro-framework — PSR-7/11/15, autowiring DI, routing, and zero config

README 文档

README

Lift — a fast, minimal PHP micro-framework

Latest Version Total Downloads PHP 8.1+ PSR-7 · 11 · 15 MIT License

Documentation → getlift.dev

Lift is a PHP 8.1+ micro-framework built around PSR standards. It gives you a router, an autowiring DI container, PSR-7 request/response objects, and a PSR-15 middleware pipeline — everything you actually need, nothing you don't.

Installation

composer require malinichevvv/lift-php

Quick start

<?php
require 'vendor/autoload.php';

use Lift\App;
use Lift\Http\Request;
use Lift\Http\Response;

$app = new App();

$app->get('/', fn() => ['message' => 'Hello, World!']);

$app->get('/users/{id:\d+}', function (Request $req) use ($repo) {
    $user = $repo->find((int) $req->param('id'));
    return $user ?? throw new \Lift\Exception\NotFoundException();
});

$app->post('/users', function (Request $req) use ($repo) {
    $data = $req->validate([
        'name'  => 'required|string|max:255',
        'email' => 'required|email',
    ]);
    return Response::json($repo->create($data), 201);
});

$app->run();

No config files. No service providers. No magic — just PHP.

Starter project

Prefer a ready-made project layout over a single file? Scaffold one with Composer:

composer create-project malinichevvv/lift-skeleton myapp
cd myapp && composer serve

lift-skeleton is a small URL-shortener microservice — a working example of attribute routing, request validation, migrations, a cache layer, per-route middleware, a custom console command, and feature tests.

What's included

Feature
Router Named routes, regex constraints, groups, attribute routing
DI Container PSR-11, full autowiring, circular dependency detection
HTTP Immutable PSR-7 Request/Response, cookies, file uploads
Middleware PSR-15 pipeline, global / group / per-route
Database Query builder, migrations, models, transactions, pessimistic locks
Validation 60+ rules, custom messages, FormRequest
Console CLI framework, scaffolding generators, interactive REPL
Views Template engine with layouts, partials, and asset helpers
Queue Sync, Database, Redis, AMQP drivers + worker
Cache PSR-16, File, Redis, Database backends
Events PSR-14 dispatcher
HTTP Client Fluent wrapper for ext-curl
Auth/Crypto JWT, HMAC, Bcrypt, AES-256-GCM
OpenAPI Attribute-driven spec generation
SSE Server-Sent Events response
Testing Built-in TestCase with HTTP helpers
Debug Dev toolbar with SQL, request, performance, and error tabs

Routing

$app->get('/path',    $handler);
$app->post('/path',   $handler);
$app->put('/path',    $handler);
$app->patch('/path',  $handler);
$app->delete('/path', $handler);
$app->any('/path',    $handler);
$app->map(['GET', 'POST'], '/path', $handler);

Any callable works as a handler — closure, [Class::class, 'method'], invokable class, or function name. Dependencies are autowired from the container automatically.

// Regex-constrained parameter
$app->get('/posts/{id:\d+}', fn(Request $req) => ['id' => (int) $req->param('id')]);

// Named route + URL generation
$app->get('/users/{id}', $h)->name('users.show');
$app->url('users.show', ['id' => 42]); // → /users/42

// Group with shared prefix + middleware
$app->group('/api/v1', function ($g) {
    $g->get('/users',      [UserController::class, 'index']);
    $g->post('/users',     [UserController::class, 'store']);
    $g->get('/users/{id}', [UserController::class, 'show']);
})->middleware(AuthMiddleware::class);

DI Container

// Bind interface → concrete class (autowired)
$app->bind(UserRepositoryInterface::class, MySQLUserRepository::class);

// Singleton factory
$app->singleton(Connection::class, fn() => Connection::fromEnv());

// Pre-built instance
$app->instance(Config::class, $config);

// Inject anywhere via type-hint — Lift resolves it automatically
$app->get('/users', function (Request $req, UserRepository $repo) {
    return $repo->all();
});

Error handling

use Lift\Debug\ErrorRenderer;

// Content-negotiating handler — JSON for API clients, HTML for browsers
$app->onError(ErrorRenderer::auto());

// Or custom
$app->onException(\Lift\Exception\NotFoundException::class, fn() =>
    Response::json(['error' => 'Not found'], 404)
);

Testing

App::handle(Request): Response never touches $_SERVER or php://input, so tests need no HTTP server:

use Lift\Testing\TestCase;

final class UserApiTest extends TestCase
{
    public function testCreateUser(): void
    {
        $res = $this->post('/users', ['name' => 'Alice', 'email' => 'alice@example.com']);

        $this->assertStatus(201, $res);
        $this->assertJsonContains(['name' => 'Alice'], $res);
    }
}

Requirements

  • PHP 8.1+
  • Composer

Optional extensions unlock specific features (ext-redis, ext-pcntl, ext-curl, ext-pdo). The core framework works without any of them.

Documentation

Full docs with examples for every feature: getlift.dev

License

MIT © Vladyslav Malinichiev

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固