check24/apitk-dtomapper-bundle
UserV1, UserV2), which is critical for backward compatibility in RESTful APIs.AppServiceProvider or custom container binding.@Dto\View) may need replacement with Laravel’s native attributes or custom middleware.@Route vs. Laravel’s Route::get).ApiResources (Spatie) or Transformer patterns (Fractal)?
/v1/users and /v2/users require custom middleware or subdomain routing?league/fractal)?ApiResources)./v1/, /v2/ endpoints).composer require check24/apitk-dtomapper-bundle
AppServiceProvider:
public function register()
{
$this->app->bind('dto.mapper', function () {
return new \Shopping\ApiTKDtoMapperBundle\DtoMapper\MapperRegistry();
});
}
app/DtoMapper/ directory.MapperInterface for each DTO (e.g., UserV1Mapper, ProductV2Mapper).@Rest\View with custom middleware or Laravel attributes to trigger DTO mapping.public function handle($request, Closure $next)
{
$response = $next($request);
if ($response->getData() instanceof DtoInterface) {
$response->setContent($this->serializeDto($response->getData()));
}
return $response;
}
Route::prefix('v1')->group(function () {
Route::get('/users', [UserController::class, 'index']);
});
@DtoMapper\View won’t work natively in Laravel.UserV1, OrderV1).@Rest\View responses with DTO mappers.UserV1 → UserV2).@DtoMapper\View annotations.\Log::debug('DTO mapped', ['dto' => $dto, 'source' => $data]);
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Mapper throws exception | API returns 500 | Wrap in try-catch, return 400 with error DTO. |
| Unsupported DTO version | 404 or 500 | Use route middleware to reject unsupported versions. |
| Circular references in mapping | Infinite loop | Implement depth limits or cycle detection. |
| Package abandonment | No updates | Fork or rewrite mappings using Laravel’s native tools. |
*V1Mapper naming).MapperInterface implementations.php artisan make:dto-mapper User
How can I help you explore Laravel packages today?