Framework-agnostic REST controller toolkit in vanilla PHP. - Router with path parameters, 404 and 405 with an Allow header. - Immutable Request, JsonRequest and Response; nothing is printed. - CrudController over a ResourceGateway port the application implements. - Composable Middleware/Pipeline chain. - Security middlewares: BearerAuth, RequireRole, RateLimit, Cors. - Transport middlewares: Logging, ContentNegotiation. - Nine typed HTTP exceptions with snake_case JSON bodies. - Declares PHP >=8.3 and no dependency on an ORM: ports are local. - MIT license.
23 lines
556 B
PHP
23 lines
556 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Camelia\Controllers;
|
|
|
|
/**
|
|
* Cross-cutting step that wraps a handler.
|
|
*
|
|
* A middleware either delegates by calling `$next($request)` or short-circuits by returning a
|
|
* `Response` without calling it. PSR-15 shaped, minus the external dependency: the library stays
|
|
* framework-free.
|
|
*
|
|
* @see \Camelia\Controllers\Pipeline which composes them.
|
|
*/
|
|
interface Middleware
|
|
{
|
|
/**
|
|
* @param callable(Request): Response $next
|
|
*/
|
|
public function process(Request $request, callable $next): Response;
|
|
}
|