Documentation / OmniPHP
HTTP & middleware
Route requests through a lightweight, explicit HTTP pipeline.
Routes and groups
Router supports HTTP methods, grouped prefixes and route parameters. Context exposes inputs, headers, query parameters and response helpers. ResponseMiddleware turns returned data into the framework response envelope.
use OmniPHP\Http\{Context, Router};
use OmniPHP\Http\Middlewares\ResponseMiddleware;
Router::group('/api', function () {
Router::get('/books/{id}', function (Context $ctx) {
return ['id' => $ctx->param('id')];
});
Router::post('/books', function (Context $ctx) {
return ['title' => $ctx->input('title')];
});
}, [new ResponseMiddleware()]);Middleware
Implement Middleware and call the next handler to continue the onion pipeline. Use Context for request-scoped values rather than writing mutable globals.
use OmniPHP\Http\{Context, Middleware};
use OmniPHP\Http\Router;
class RequestContext implements Middleware
{
public function handle(Context $ctx, callable $next): mixed
{
$ctx->set('request_started_at', microtime(true));
return $next($ctx);
}
}
Router::middleware(new RequestContext());WebSocket
OmniPHP\WebSocket provides Context, Broadcaster and Gateway. Attach the relevant handlers to a Workerman WebSocket worker and manage connection lifecycle explicitly.