mini\Controller\ConverterHandler
class
Documentation
Request handler that converts controller method return values to PSR-7 responses
This handler wraps a controller method callable and automatically converts its return value to a ResponseInterface using the converter registry.
Conversion flow:
- Invoke the controller method with URL parameters from request attributes
- If return value is already ResponseInterface, return it directly
- Otherwise, use converter registry to convert return value to ResponseInterface
- If no converter found, throw RuntimeException
This enables controllers to return any type (arrays, strings, domain objects) without manually creating Response objects.
Example:
// Controller method returns array
public function index(): array {
return ['users' => $this->users];
}
// ConverterHandler converts array → ResponseInterface via registered converter
$handler = new ConverterHandler($this->index(...));
$response = $handler->handle($request); // JSON response
Inheritance
Implements:
Psr\Http\Server\RequestHandlerInterface
Properties (1)
private
readonly
mixed $handler
Methods (3)
Documentation missing
Handle the request by invoking the controller method and converting its return value
Invoke the handler with dependency injection from request attributes