api-platform / api-platform/core

DTO as resource - auto convert subresource identifiers to objects

未关闭
#8,094 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
PHP
星标
2.6k
派生
980
平均合并
2 天 4 小时
30 天内合并 PR
49

描述

Hi,

I've created subresource. This resource is DTO, not an entity.

```php
#[ApiResource(
operations: [
new Post(
uriTemplate: '/events/{eventId}/participants/{participantId}/images.{_format}',
uriVariables: [
# possible bug below
'eventId' => new Link(fromClass: EventResource::class, toProperty: 'event'),
'participantId' => new Link(fromClass: EventParticipantResource::class, toProperty: 'participant'),
],
processor: CreateEventParticipantImageProcessor::class,
),
/** ... */
readonly class EventParticipantImageResource
```

Problem is that in `CreateEventParticipantImageProcessor` I can use only uri variables cause query is not serialized:
```php
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []) {
$eventId = $uriVariables['eventId']; # identifier
$eventId = $data->event?->id; # null
}
```

Is there functionality that will convert identifiers to target resources and assign to DTO fields so I can use `$data->event?->id`?

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。