Skip to content

Commit

Permalink
doc(UploadFile): fix #1893 doc of Uploading to an Existing Resource w…
Browse files Browse the repository at this point in the history
…ith its Fields (#1897)

- Adding the getSupport method to make the class compatible with Symfony 7.
- Switching from UploadedFile to File for consistency with Vich.

Co-authored-by: Kinhelm <kinhelm@localhost>
  • Loading branch information
kinhelm and Kinhelm committed Mar 18, 2024
1 parent 7cc70df commit 2b0a32c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/file-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,28 @@ We also need to make sure the field containing the uploaded file is not denormal

namespace App\Serializer;

use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

final class UploadedFileDenormalizer implements DenormalizerInterface
{
public function denormalize($data, string $type, string $format = null, array $context = []): UploadedFile
public function denormalize($data, string $type, string $format = null, array $context = []): File
{
return $data;
}

public function supportsDenormalization($data, $type, $format = null): bool
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
{
return $data instanceof File;
}

public function getSupportedTypes(?string $format): array
{
return $data instanceof UploadedFile;
return [
'object' => null,
'*' => false,
File::class => true,
];
}
}
```
Expand Down

0 comments on commit 2b0a32c

Please sign in to comment.