外观主题
Laravel / ThinkPHP / PSR-7 多框架接入
磐台内核采用零框架设计,通过薄适配器无缝运行在 Laravel 10/11/12、ThinkPHP 8、PSR-7(Slim / Symfony / Mezzio) 及 原生 PHP SAPI 之上。完整可运行骨架位于 packages/php/examples/laravel-11/ 与 packages/php/examples/thinkphp-8/。
1. Laravel 10 / 11 / 12 接入
php
<?php
use Plinth\DeckCore\Core\Http\DeckCoreKernel;
use Plinth\DeckCore\Laravel\Http\LaravelHttpAdapter;
use Plinth\DeckCore\Laravel\LaravelHostBridge;
// 1. 在 AppServiceProvider::boot() 中绑定宿主运行时
LaravelHostBridge::boot([
'defaultDbConnection' => 'mysql',
]);
// 2. 组装 Kernel(挂载标准宿主与所需功能中心)
$kernel = (new DeckCoreKernel())->mountStandardHost();
// 3. 在 routes/web.php 或控制器中委托分发
$spec = $kernel->handle(LaravelHttpAdapter::fromRequest($request));
return LaravelHttpAdapter::toResponse($spec);2. ThinkPHP 8 接入
php
<?php
use Plinth\DeckCore\Core\Http\DeckCoreKernel;
use Plinth\DeckCore\DataExport\DataExportHandler;
use Plinth\DeckCore\DocCenter\DocCenterHandler;
use Plinth\DeckCore\Notification\NotificationHandler;
use Plinth\DeckCore\Task\TaskHandler;
use Plinth\DeckCore\ThinkPHP8\Http\ThinkPHP8HttpAdapter;
use Plinth\DeckCore\ThinkPHP8\ThinkPHP8HostBridge;
// 1. AppService::boot() 中注册 ThinkPHP 8 宿主桥接
ThinkPHP8HostBridge::boot([
'defaultDbConnection' => 'mysql',
]);
// 2. 一键挂载标准宿主 + 四大功能中心(通知 / 任务 / 文档 / 导数)
$kernel = (new DeckCoreKernel())
->mountStandardHost()
->mount(new NotificationHandler())
->mount(new TaskHandler())
->mount(new DocCenterHandler())
->mount(new DataExportHandler());
// 3. 路由入口分发
$spec = $kernel->handle(ThinkPHP8HttpAdapter::fromRequest($request));
return ThinkPHP8HttpAdapter::toResponse($spec);3. PSR-7 / Slim / Symfony / 原生 PHP SAPI
php
<?php
use Plinth\DeckCore\Core\Database\PdoConnection;
use Plinth\DeckCore\Core\Http\DeckCoreKernel;
use Plinth\DeckCore\Core\Http\RequestContext;
use Plinth\DeckCore\Core\Runtime\HostRuntime;
use Plinth\DeckCore\Psr\PsrHttpAdapter;
$pdoConn = PdoConnection::fromDsn(
'mysql:host=127.0.0.1;dbname=app;charset=utf8mb4',
$user,
$pass
);
HostRuntime::configure([
'rootPath' => dirname(__DIR__),
'runtimePath' => dirname(__DIR__) . '/runtime',
'dbResolver' => function ($name = '') use ($pdoConn) {
return $pdoConn;
},
]);
$kernel = (new DeckCoreKernel())->mountStandardHost();
// PSR-7 宿主:
$psrResponse = PsrHttpAdapter::handle($kernel->dispatcher(), $psrRequest, $psr17ResponseFactory);
// 或原生 PHP SAPI 直接输出:
// PsrHttpAdapter::emit($kernel->handle(RequestContext::fromGlobals()));4. 挂载通用 CRUD 资源页与高密报表页
业务页面无需手写重复的增删改查接口,挂载 ResourcePageHandler 或 ReportPageHandler 即可自动暴露全套 Schema 驱动端点:
php
<?php
use Plinth\DeckCore\Core\Http\ReportPageHandler;
use Plinth\DeckCore\Core\Http\ResourcePageHandler;
// 通用 CRUD 资源页:自动注册 schema / data / save / record / fieldOptions /
// uploadField / inlineEdit / batch / export / deleteRow
$kernel->mount(
new ResourcePageHandler($resourcePageRuntime),
'/api/deckcore/orders'
);
// 通用高密报表页:自动注册 schema / data(含 NDJSON 流式分片)/ export(CSV & Excel)/ fieldOptions
$kernel->mount(new ReportPageHandler([
'schema' => $schemaArrayOrCallable,
'model' => $reportModel,
'config' => $reportConfigBuilder,
]), '/api/deckcore/report/revenue');