api-platform / api-platform/core
DTO as resource - auto convert subresource identifiers to objects
- Lingua principale
- PHP
- Stelle
- 2.6k
- Fork
- 980
- Merge medio
- 2g 4h
- PR unite (30g)
- 49
Descrizione
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`?
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.