-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
I am struggling now since hours, maybe I am doing something wrong, maybe there is a bug or it's just not possible.
Basically I have a collection in the src and the target-object. The elements are all of the same type (typehinted, docblocks, everything there).
But I am no capable to map the elements from the source-objects collection to the type of the target-objects collection.
The elements of the collection are mapped but not to the target type :-(
Again, please apologize if I missed that somewhere in the documentation.
Call
assert($searchResult instanceof LegacyPaginatedData);
$response = $autoMapper->map($searchResult, UserSubusersResponse::class, [
'groups' => ['user:subuser'],
]);
Result
UserSubusersResponse::$currentPage is fine.
UserSubusersResponse::$data is a collection of UserEntities (instead of a collection of UserSubuserResources)
Target-Objects
// Target (Root)
#[Groups(['user:subuser'])]
final class UserSubusersResponse
{
#[MapFrom(LegacyPaginatedData::class)]
public int $currentPage;
/** @var iterable<UserSubuserResource> */
#[MapFrom(LegacyPaginatedData::class)]
public iterable $data = [];
}
#[Groups(['user:subuser'])]
final class UserSubuserResource
{
#[MapFrom(User::class, property: 'uid')]
public int $uid;
#[MapFrom(User::class)]
public string $email;
}
Source-Objects
/**
* @template T
*/
#[Groups(['user:subuser'])]
final readonly class LegacyPaginatedData
{
/**
* @param iterable<T> $data
*/
private function __construct(
/** @var iterable<T> */
public array $data,
public int $currentPage,
public int $currentPageSize,
public int $pageCount,
public int $totalCount,
public string $orderBy = 'timeCreated',
public string $orderDirection = 'ASC',
) {
}
}
#[Groups(['user:subuser'])]
class UserEntity {
// protected properties and public getters
}
Metadata
Metadata
Assignees
Labels
No labels