Adaptism is a package that finds adapters for objects using a dispatch map.
Adapters can be annotated with attributes for discovery.
use Ock\Adaptism\Tests\Fixtures\Color\Hex\HexColorInterface; use Ock\Adaptism\Tests\Fixtures\Color\Rgb\RgbColor; use Ock\Adaptism\UniversalAdapter\UniversalAdapterInterface; function f(UniversalAdapterInterface $universalAdapter): void { $rgb = new RgbColor(255, 0, 0); $hex = $universalAdapter->adapt($rgb, HexColorInterface::class); assert($hex instanceof HexColorInterface); assert($hex->getHexCode() === 'ff0000'); }use Ock\Adaptism\Attribute\Adapter; use Ock\Adaptism\Attribute\Parameter\Adaptee; use Ock\Adaptism\Tests\Fixtures\Color\Hex\HexColorInterface; use Ock\Adaptism\Tests\Fixtures\Color\Rgb\RgbColor; use Ock\Adaptism\Tests\Fixtures\Color\Rgb\RgbColorInterface; class C { #[Adapter] public static function adapt( #[Adaptee] RgbColorInterface $rgb, ): HexColorInterface { return new RgbColor( sprintf( '%02x%02x%02x', $rgbColor->red(), $rgbColor->green(), $rgbColor->blue())); } }Study the tests!

