Aplikasi Keuangan yang mengatur lalu lintas transaksi antara bank dan aplikasi internal Kampus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

39 lines
1.0 KiB

<?php
namespace App\Domains\Channel\Support\Mapper;
use App\Domains\Channel\Enums\Api\ApiType;
use App\Domains\System\Support\Integration\DataPayloadMapper;
use InvalidArgumentException;
class ApiMapperRegistry
{
/**
* @var array<string, class-string<DataPayloadMapper>>
*/
protected static array $mappers = [];
/**
* Register mapper with type-safe using enum ApiType
*/
public static function register(ApiType $type, string $mapperClass): void
{
static::$mappers[$type->value] = $mapperClass;
}
/**
* @param ApiType $type
* @throws InvalidArgumentException
* @return DataPayloadMapper
*/
public static function resolve(ApiType $type): DataPayloadMapper
{
$mapperClass = static::$mappers[$type->value] ?? null;
if (! $mapperClass || ! class_exists($mapperClass)) {
throw new InvalidArgumentException("No DataMapper registered for ApiType: {$type->value}");
}
return app($mapperClass);
}
}