定制 maplephp/emitron 二次开发

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

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

maplephp/emitron

Composer 安装命令:

composer require maplephp/emitron

包简介

MaplePHP Emitron is lightweight PSR-15 kernel and middleware engine that follows PSR conventions with built-in emitter, kernel, and middlewares for clean, consistent request handling.

README 文档

README

Emitron is a modern PSR-based middleware and kernel library designed to handle every step of the HTTP lifecycle, from incoming request to emitted response. It’s built for developers who want clean architecture, predictable behavior, and full control without having to reinvent the wheel.

Out of the box, Emitron provides a complete runtime foundation that follows best practices across PSR-7, PSR-11, and PSR-15. It includes a configurable middleware pipeline, an emitter that handles headers and body output, and a kernel that automatically boots your container, initializes requests, responses, streams, and emits the final output.

Whether you’re building your own framework, an HTTP microservice, or a CLI-driven application, Emitron gives you a consistent, extensible core that plays well with any PSR-compliant ecosystem — simple when you need it, powerful when you don’t.

Features

  • Fully PSR-15 compliant middleware dispatcher
  • Works with any PSR-7 request and response library
  • Lightweight and framework-agnostic
  • Supports automatic bootstrapping via the Kernel
  • Built-in middlewares for common HTTP tasks (output buffering, compression, content length, HEAD requests, etc.)
  • Compatible with any PSR-11 container

Installation

composer require maplephp/emitron

Middleware Example

Emitron includes a robust request handler that executes PSR-15 middlewares in sequence, returning a fully PSR-7 compliant response.

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use MaplePHP\Emitron\RequestHandler;
use MaplePHP\Emitron\Emitters\HttpEmitter;
use MaplePHP\Http\Environment;
use MaplePHP\Http\ServerRequest;
use MaplePHP\Http\Uri;
use MaplePHP\Emitron\Middlewares\{
    ContentLengthMiddleware,
    GzipMiddleware,
    HeadRequestMiddleware
};
use App\Controllers\MyController;

// Use MaplePHP HTTP library or any other PSR-7 implementation
$env = new Environment();
$request = new ServerRequest(new Uri($env->getUriParts($parts)), $env);

// Add your middlewares — Emitron ships with several ready-to-use
$middlewares = [
    new OutputBufferMiddleware(),   // Inject ob_get_clean() into stream
    new GzipMiddleware(),           // Compress body, update Content-Encoding
    new ContentLengthMiddleware(),  // Recalculate body size
    new HeadRequestMiddleware(),    // Optionally blank body
    new EmitterMiddleware(),        // Emit headers + body
];

// Run the middleware stack


$factory = new ResponseFactory($bodyStream);
// $finalHandler = new ControllerRequestHandler($factory, [MyController::class, "index"]);
$finalHandler = new ControllerRequestHandler($factory, function(RequestInterface $request, ResponseInterface $response) {
    $response->getBody()->write("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
    return $response;
});

$handler = new RequestHandler($middlewares, $finalHandler);
$response = $handler->handle($request);

// Emit the execute headers and response correctly 
//$emit = new CliEmitter($response, $request);
$emit = new HttpEmitter();
$emit->emit($response, $request);

Each middleware conforms to Psr\Http\Server\MiddlewareInterface, allowing you to plug in your own or third-party middlewares with no additional setup.

Kernel and Emitter

Emitron’s Kernel provides an all-in-one entry point for bootstrapping and executing your application. It automatically initializes the request, response, stream, container, and middlewares, following PSR conventions.

use MaplePHP\Emitron\Kernel;use MaplePHP\Http\Environment;use MaplePHP\Http\ServerRequest;use MaplePHP\Http\Uri;

$env = new Environment();
$request = new ServerRequest(new Uri($env->getUriParts($parts)), $env);

$kernel = new Kernel(new Container(), [
    new OutputBufferMiddleware(),
    new GzipMiddleware(),
    new ContentLengthMiddleware(),
    new HeadRequestMiddleware(),
    new EmitterMiddleware()
]);

$kernel->run($request);

The Kernel takes three arguments:

$kernel = new Kernel(
    Psr\Container\ContainerInterface, 
    [Psr\Http\Server\MiddlewareInterface::class], 
    ?MaplePHP\Emitron\Contracts\DispatchConfigInterface
);

⚙️ Custom Configuration

Emitron supports custom configuration files. Provide a PHP file that returns an array, and Emitron will pass it to the PSR container under the key 'configuration'.

use MaplePHP\Emitron\DispatchConfig;use MaplePHP\Emitron\Kernel;

$config = new DispatchConfig(__DIR__ . '/config/app.php');

$kernel = new Kernel(new Container(), [
    new ContentLengthMiddleware(),
    new HeadRequestMiddleware(),
], $config);
// You can also return the path in you app if you want with:
// $configPath = Kernel::getConfigFilePath();

Example config/app.php:

<?php

return [
    'app_name' => 'MyApp',
    'debug' => true,
    'timezone' => 'Europe/Stockholm',
];

maplephp/emitron 适用场景与选型建议

maplephp/emitron 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 118 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「middleware」 「http-kernel」 「php-framework」 「psr-15」 「request-handler」 「http-emitter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 maplephp/emitron 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 maplephp/emitron 我们能提供哪些服务?
定制开发 / 二次开发

基于 maplephp/emitron 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2026-01-12