mark-gerarts/auto-mapper-plus
AutoMapper+ transfers data between PHP objects with minimal boilerplate, inspired by .NET AutoMapper. Define mappings with custom callbacks and operations, handle nested objects, construction, naming conventions, and map arrays/stdClass with configurable options.
Pros:
bind()) for dependency injection, mirroring Laravel’s native DI patterns.Cons:
User::class mapped to UserDto::class with these transformations?").Mockery for mocking mappers, Pest/PHPUnit for assertions).User → UserResource).DB::select() → structured responses).rebing/graphql-laravel for resolving complex types.pest).Xdebug or Blackfire.MappingRegistry class).ValidatesWhenResolved or custom validation rules to ensure source objects meet mapping requirements.Log facade) and alert on anomalies.spatie/laravel-data, laravel-shift/doctrine-types)?phpdocumentor)?$app->bind(AutoMapperInterface::class, function ($app) {
$config = new AutoMapperConfig();
// Register mappings here or via config files.
return new AutoMapper($config);
});
config/automapper.php for environment-specific overrides.App\Providers\AutoMapperServiceProvider).MapFrom with GraphQL field resolvers).UserEntity → UserDomainObject).CreateUserRequest → CreateUserCommand).User → UserDto).age calculation).Post → PostResource with AuthorResource).User::all() → UserResource::collection()).ReflectionClass).make:command to validate existing mappings against AutoMapper+ rules.symfony/options-resolver).spatie/laravel-api-resources for serialization.rebing/graphql-laravel for type resolution.pestphp/pest, mockery/mockery, and laravel/testbench.composer require mark-gerarts/auto-mapper-plus.AppServiceProvider or a dedicated provider.config/automapper.php or via code.'mappings' => [
App\Models\User::class => App\DTO\UserDto::class,
App\Models\Post::class => App\DTO\PostDto::class,
],
'operations' => [
App\DTO\UserDto::class => [
'age' => Operation::mapFrom(fn ($user) => now()->year - $user->birth_year),
],
],
AutoMapperInterface into services/controllers.$mapper->map($entity, Dto::class).UserTest → testMapUserToDto).RefreshDatabase trait for integration tests.try-catch blocks around $mapper->map()).failed-job monitoring for async mapping tasks.How can I help you explore Laravel packages today?