[■]
codesaur/http-application
1=[↕]
1:1 ══ composer require codesaur/http-application
codesaur/http-application · v7.0.1
HTTP Application
Lightweight, flexible HTTP Application core compliant with PSR-7 & PSR-15
[■]
HTTP Application
A minimalist, middleware-based Application core built on PSR-7 (HTTP Message) and PSR-15 (RequestHandler / Middleware). Combine routers (one or many), middleware, controller/action handlers, closure routes and an exception handler in a few lines of code to build the application structure you want.
Features
- PSR-7 standard ServerRequest + Response
- PSR-15 Middleware & RequestHandler chain (onion model)
- Multi-router delegation - combine several Routers in one Application
- Mount an Application at a URL prefix - Routers stay reusable
- override() lane for explicitly replacing previously registered routes
- Optional Controller base class
- Per-route middleware (MiddlewareInterface, Closure, class-string)
- Exception Handler with development mode
Core classes
| Class | Purpose |
|---|---|
Application | Middleware stack, router collection, mount, handle() |
Controller | Base class for controller/action style with request helpers |
ExceptionHandler | Middleware turning exceptions into HTTP responses |
ExceptionHandlerInterface | Contract for custom exception handlers |
Quick example
use codesaur\Router\Router;
use codesaur\Http\Application\Application;
use codesaur\Http\Application\ExceptionHandler;
use codesaur\Http\Message\ServerRequest;
use codesaur\Http\Message\NonBodyResponse;
// Router-д route бүртгэх / Register routes on Router
$router = new Router();
$router->GET('/', function ($req) {
echo 'Hello World!';
});
$router->GET('/user/{int:id}', [UserController::class, 'show'])->name('user.show');
// Application үүсгэх + middleware + router нэмэх
$app = new Application(new NonBodyResponse());
$app->use(new ExceptionHandler());
$app->use(new AuthMiddleware());
$app->use($router);
$app->mount('/dashboard'); // бүх route /dashboard prefix-тэй болов
// Хүсэлт боловсруулах / Handle request
$request = (new ServerRequest())->initFromGlobal();
$response = $app->handle($request);
Running tests
composer test
[■]
Info
Install
composer require codesaur/http-application
Requirements
- PHP 8.2.1+
- Composer
- PSR-7 implementation (codesaur/http-message)
Dependencies (codesaur)
- codesaur/router ^6.0.1
Documentation