api-platform / api-platform/core

DTO as resource - auto convert subresource identifiers to objects

Abierto
#8,094 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
PHP
Estrellas
2.6k
Forks
980
Merge medio
2 d 4 h
PR fusionados (30 d)
49

Descripción

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`?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.