api-platform / api-platform/core

DTO as resource - auto convert subresource identifiers to objects

Ouverte
#8,094 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
PHP
Étoiles
2.6k
Forks
980
Merge moyen
2 j 4 h
PR mergées (30 j)
49

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.