PHPackages                             georgeff/http-kernel - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. georgeff/http-kernel

ActiveLibrary[HTTP &amp; Networking](/categories/http)

georgeff/http-kernel
====================

PSR-15 HTTP kernel. Provides routing, a global middleware stack, per-route middleware, exception handling, and response emission

1.0.0(2mo ago)09MITPHPPHP ^8.2CI passing

Since Feb 22Pushed 2mo agoCompare

[ Source](https://github.com/MikeGeorgeff/http-kernel)[ Packagist](https://packagist.org/packages/georgeff/http-kernel)[ RSS](/packages/georgeff-http-kernel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (10)Versions (2)Used By (0)

HTTP Kernel
===========

[](#http-kernel)

A PSR-15 HTTP kernel built on top of [`georgeff/kernel`](https://github.com/MikeGeorgeff/kernel). Provides routing, a global middleware stack, per-route middleware, exception handling, and response emission.

Installation
------------

[](#installation)

```
composer require georgeff/http-kernel
```

Quick Start
-----------

[](#quick-start)

```
use Georgeff\HttpKernel\HttpKernel;
use Georgeff\Kernel\Environment;

$kernel = new HttpKernel(Environment::Production);

$kernel->addMiddleware(SessionMiddleware::class);

$kernel->addRoute('GET', '/users/{id}', UserHandler::class);

$kernel->withExceptionHandler(function (Throwable $e, ServerRequestInterface $request) {
    $status = $e instanceof HttpExceptionInterface ? $e->getStatusCode() : 500;
    return new JsonResponse([
        'error' => $e->getMessage(),
    ], $status);
});

$kernel->boot();
$kernel->run();
```

Routing
-------

[](#routing)

Routes are registered before boot via `addRoute()`. The handler can be a `RequestHandlerInterface` instance or a string service ID resolved from the container.

```
// Single method
$kernel->addRoute('GET', '/users', ListUsersHandler::class);

// Multiple methods
$kernel->addRoute(['GET', 'POST'], '/users', UsersHandler::class);
```

Route parameters are available through the matched route object, which is stored as the `__route__` request attribute:

```
$route = $request->getAttribute('__route__');
$id = $route->getArgument('id');
```

### Per-Route Middleware

[](#per-route-middleware)

Routes support their own middleware stack, processed in FIFO order before the route handler:

```
$route = $kernel->addRoute('GET', '/admin', AdminHandler::class);
$route->addMiddleware(AuthMiddleware::class)
      ->addMiddleware(RoleMiddleware::class);
```

Middleware
----------

[](#middleware)

Global middleware is added before boot and runs on every request in FIFO order:

```
$kernel->addMiddleware(CorsMiddleware::class);
$kernel->addMiddleware($loggingMiddleware);
```

Middleware can be a `MiddlewareInterface` instance or a string service ID resolved from the container.

Exception Handling
------------------

[](#exception-handling)

Register an exception handler to convert exceptions into HTTP responses. Without a handler, exceptions are rethrown. The handler receives the raw `Throwable` — check `instanceof HttpExceptionInterface` for HTTP-specific data.

```
$kernel->withExceptionHandler(function (Throwable $e, ServerRequestInterface $request) {
    $status = $e instanceof HttpExceptionInterface ? $e->getStatusCode() : 500;
    return new JsonResponse([
        'error' => $e->getMessage(),
    ], $status);
});
```

### HTTP Exceptions

[](#http-exceptions)

The package provides a set of HTTP exception classes:

ClassStatus`BadRequestHttpException`400`UnauthorizedHttpException`401`ForbiddenHttpException`403`NotFoundHttpException`404`MethodNotAllowedHttpException`405`NotAcceptableHttpException`406`RequestTimeoutHttpException`408`ConflictHttpException`409`GoneHttpException`410`UnsupportedMediaTypeHttpException`415`UnprocessableEntityHttpException`422`TooManyRequestsHttpException`429`InternalServerErrorHttpException`500`BadGatewayHttpException`502`ServiceUnavailableHttpException`503All extend `HttpException` and implement `HttpExceptionInterface`.

`MethodNotAllowedHttpException` provides `getAllowedMethods()` and `TooManyRequestsHttpException` provides `getRetryAfter()`.

Lifecycle Events
----------------

[](#lifecycle-events)

The kernel dispatches PSR-14 events at key points in the request lifecycle. Register a `Psr\EventDispatcher\EventDispatcherInterface` in the container to listen for them:

```
$kernel->addDefinition(EventDispatcherInterface::class, function () {
    return $myEventDispatcher;
});
```

EventDispatched`RequestReceived`At the start of `handle()``ResponseReady`After a response is produced`RequestErrored`When an exception is caught in `handle()``KernelTerminating`During `terminate()`, after response emissionAll events extend `Georgeff\Kernel\Event\KernelEvent` and carry the kernel instance along with relevant request, response, or exception data as readonly public properties.

Debugging
---------

[](#debugging)

Enable debug mode to profile the request lifecycle. Pass `debug: true` to the kernel constructor:

```
$kernel = new HttpKernel(Environment::Development, debug: true);
```

When debug mode is enabled, the kernel profiles the following phases:

PhaseDescription`requestResolution`Resolving the `ServerRequestInterface` from the container`handle`Total time spent in `handle()``middleware`Executing the middleware pipeline`exceptionHandling`Running the exception handler (only when an exception occurs)`emission`Emitting the response`terminate`Running termination logicThe `requestResolution`, `emission`, and `terminate` phases are only recorded when using `run()`. When calling `handle()` directly, only `handle`, `middleware`, and `exceptionHandling` (if applicable) are recorded.

Retrieve profiling data via `getDebugInfo()`:

```
$info = $kernel->getDebugInfo();

// Boot profile from the parent kernel
$info['bootProfile'];

// Request lifecycle profile
$info['requestProfile']['duration'];
$info['requestProfile']['phases']['middleware']['duration'];
```

Response Helpers
----------------

[](#response-helpers)

Convenience response classes under `Georgeff\HttpKernel\Response`:

- `JsonResponse`
- `EmptyResponse`
- `RedirectResponse`

License
-------

[](#license)

MIT

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance83

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

86d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8147ce1d901e9fa2ec95d6408e5862025211f9ae60131e41fb115a5a0916ce4?d=identicon)[georgeff](/maintainers/georgeff)

---

Top Contributors

[![MikeGeorgeff](https://avatars.githubusercontent.com/u/6169468?v=4)](https://github.com/MikeGeorgeff "MikeGeorgeff (22 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/georgeff-http-kernel/health.svg)

```
[![Health](https://phpackages.com/badges/georgeff-http-kernel/health.svg)](https://phpackages.com/packages/georgeff-http-kernel)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[cakephp/authentication

Authentication plugin for CakePHP

1153.6M67](/packages/cakephp-authentication)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[laminas/laminas-psr7bridge

Bidirectional conversions between PSR-7 and laminas-http messages

117.9M18](/packages/laminas-laminas-psr7bridge)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[openswoole/core

Openswoole core library

181.1M32](/packages/openswoole-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
