Код: Выделить всё
#[ApiPlatform\Metadata\ApiResource(
operations: [new ApiPlatform\Metadata\Post()],
processor: App\State\OrderProcessor::class,
)]
class Order
{
/** @var Product[] */
#[Symfony\Component\Validator\Constraints\Valid]
public array $products = [];
}
class Product
{
public string $name = '';
}
Код: Выделить всё
/**
* @implements ApiPlatform\State\ProcessorInterface
*/
final class OrderProcessor implements ApiPlatform\State\ProcessorInterface
{
/**
* @return App\ApiResource\Order
*/
public function process(
mixed $order,
ApiPlatform\Metadata\Operation $operation,
array $uriVariables = [],
array $context = [],
): mixed {
// $order->products is array[] with whatever was passed in the
// HTTP payload instead of Product[].
return $order;
}
}
мне нужно написать пользовательский нормализатор?>
Подробнее здесь: https://stackoverflow.com/questions/795 ... ctrine-orm
Мобильная версия