Skip to content

Commit

Permalink
remove a deprecation in upload docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Jan 11, 2024
1 parent c15749d commit d20ca91
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions core/file-upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ to make it look like this.

```yaml
# api/config/packages/vich_uploader.yaml

vich_uploader:
db_driver: orm
metadata:
Expand All @@ -34,7 +35,7 @@ vich_uploader:
uri_prefix: /media
upload_destination: '%kernel.project_dir%/public/media'
# Will rename uploaded files using a uniqueid as a prefix.
namer: Vich\UploaderBundle\Naming\OrignameNamer
namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
```
## Uploading to a Dedicated Resource
Expand All @@ -53,6 +54,7 @@ The `MediaObject` resource is implemented like this:
```php
<?php
// api/src/Entity/MediaObject.php
namespace App\Entity;
use ApiPlatform\Metadata\ApiProperty;
Expand Down Expand Up @@ -109,7 +111,7 @@ class MediaObject
#[Groups(['media_object:read'])]
public ?string $contentUrl = null;
#[Vich\UploadableField(mapping: "media_object", fileNameProperty: "filePath")]
#[Vich\UploadableField(mapping: 'media_object', fileNameProperty: 'filePath')]
#[Assert\NotNull(groups: ['media_object_create'])]
public ?File $file = null;
Expand Down Expand Up @@ -172,12 +174,11 @@ A [normalizer](serialization.md#normalization) could be used to set the `content
namespace App\Serializer;
use App\Entity\MediaObject;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Vich\UploaderBundle\Storage\StorageInterface;
final class MediaObjectNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
final class MediaObjectNormalizer implements NormalizerAwareInterface
{
use NormalizerAwareTrait;
Expand Down Expand Up @@ -246,6 +247,7 @@ We first need to edit our Book resource, and add a new property called `image`.
```php
<?php
// api/src/Entity/Book.php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
Expand Down Expand Up @@ -406,7 +408,9 @@ final class MultipartDecoder implements DecoderInterface
{
public const FORMAT = 'multipart';

public function __construct(private RequestStack $requestStack) {}
public function __construct(private RequestStack $requestStack)
{
}

/**
* {@inheritdoc}
Expand Down Expand Up @@ -452,17 +456,11 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

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

/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = null): bool
{
return $data instanceof UploadedFile;
Expand Down

0 comments on commit d20ca91

Please sign in to comment.