issues/27: filter DTO, strip id from payloads, lifecycle updateAt

This commit is contained in:
Valery Petrov
2026-05-15 15:35:50 +03:00
committed by Valeriy Petrov
parent da5f7bb242
commit 76044381fd
22 changed files with 153 additions and 129 deletions
+2 -16
View File
@@ -52,22 +52,17 @@ final class CrudResponder
string $entityClass,
array $writeGroups,
array $readGroups,
bool $allowIdFromPayload = false,
): JsonResponse {
$payload = $this->decodePayload($request);
if ($payload === null) {
return $this->jsonError('Ожидается JSON-объект в теле запроса', Response::HTTP_BAD_REQUEST);
}
$deserializationPayload = $payload;
if (!$allowIdFromPayload) {
unset($deserializationPayload['id']);
}
unset($payload['id']);
try {
/** @var T $entity */
$entity = $this->serializer->deserialize(
$this->encodePayload($deserializationPayload),
$this->encodePayload($payload),
$entityClass,
'json',
[
@@ -78,15 +73,6 @@ final class CrudResponder
return $this->jsonError('Ошибка десериализации: ' . $e->getMessage(), Response::HTTP_BAD_REQUEST);
}
// По умолчанию публичный CRUD не принимает id от клиента. Если системной
// интеграции понадобится внешний id, конкретный вызов должен явно передать true.
if ($allowIdFromPayload && isset($payload['id']) && method_exists($entity, 'setId')) {
$id = (int) $payload['id'];
if ($id > 0) {
$entity->setId($id);
}
}
if (($validationResponse = $this->validate($entity)) !== null) {
return $validationResponse;
}