mini\Converter\ConverterRegistryInterface abstract interface

Documentation

Interface for converter registry implementations

The converter registry manages type converters that transform values from one type to another. The primary use case is converting route return values and exceptions to HTTP responses, but the system is general-purpose.

Applications register converters during bootstrap:

// bootstrap.php
use mini\Mini;
use mini\Converter\ConverterRegistryInterface;

$registry = Mini::$mini->get(ConverterRegistryInterface::class);

// Register custom converter
$registry->register(function(MyModel $model): ResponseInterface {
    return new Response(200, ['Content-Type' => 'application/json'], $model->toJson());
});

The registry provides:

  • Type-safe converter registration via typed closures
  • Union input type support (single converter handles multiple types)
  • Specificity resolution (single > union, class > interface > parent)
  • Conflict detection for overlapping registrations

Methods (6)

Register a converter

Replace an existing converter

Check if a converter exists for input to target type

Get the converter for input to target type

Convert a value to target type

Try to convert a value, returning null if no converter handles it

Source

src/Converter/ConverterRegistryInterface.php:35-180