PHPackages                             maplephp/emitron - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. maplephp/emitron

ActiveLibrary[Framework](/categories/framework)

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.

v1.2.4(3mo ago)01182Apache-2.0PHPPHP &gt;=8.2CI passing

Since Jan 12Pushed 3mo agoCompare

[ Source](https://github.com/MaplePHP/Emitron)[ Packagist](https://packagist.org/packages/maplephp/emitron)[ Docs](https://wazabii.se)[ RSS](/packages/maplephp-emitron/feed)WikiDiscussions main Synced today

READMEChangelog (8)Dependencies (8)Versions (10)Used By (2)

MaplePHP Emitron
================

[](#maplephp-emitron)

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
--------

[](#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
------------

[](#installation)

```
composer require maplephp/emitron
```

---

Middleware Example
------------------

[](#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
------------------

[](#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
-----------------------

[](#️-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`:

```
