Skip to content

Commit 6935df3

Browse files
committed
Merge 3.2
2 parents 67f398f + 80bcedd commit 6935df3

14 files changed

+94
-107
lines changed

core/file-upload.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ to make it look like this.
2525

2626
```yaml
2727
# api/config/packages/vich_uploader.yaml
28+
2829
vich_uploader:
2930
db_driver: orm
3031
metadata:
@@ -34,7 +35,7 @@ vich_uploader:
3435
uri_prefix: /media
3536
upload_destination: '%kernel.project_dir%/public/media'
3637
# Will rename uploaded files using a uniqueid as a prefix.
37-
namer: Vich\UploaderBundle\Naming\OrignameNamer
38+
namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
3839
```
3940
4041
## Uploading to a Dedicated Resource
@@ -53,6 +54,7 @@ The `MediaObject` resource is implemented like this:
5354
```php
5455
<?php
5556
// api/src/Entity/MediaObject.php
57+
5658
namespace App\Entity;
5759
5860
use ApiPlatform\Metadata\ApiProperty;
@@ -109,7 +111,7 @@ class MediaObject
109111
#[Groups(['media_object:read'])]
110112
public ?string $contentUrl = null;
111113
112-
#[Vich\UploadableField(mapping: "media_object", fileNameProperty: "filePath")]
114+
#[Vich\UploadableField(mapping: 'media_object', fileNameProperty: 'filePath')]
113115
#[Assert\NotNull(groups: ['media_object_create'])]
114116
public ?File $file = null;
115117
@@ -172,12 +174,11 @@ A [normalizer](serialization.md#normalization) could be used to set the `content
172174
namespace App\Serializer;
173175
174176
use App\Entity\MediaObject;
175-
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
176177
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
177178
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
178179
use Vich\UploaderBundle\Storage\StorageInterface;
179180
180-
final class MediaObjectNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
181+
final class MediaObjectNormalizer implements NormalizerAwareInterface
181182
{
182183
use NormalizerAwareTrait;
183184
@@ -224,17 +225,23 @@ your data, you will get a response looking like this:
224225

225226
### Accessing Your Media Objects Directly
226227

227-
You will need to modify your Caddyfile to allow the above `contentUrl` to be accessed directly. If you followed the above configuration for the VichUploaderBundle, that will be in `api/public/media`. Add your folder to the list of path matches, e.g. `|^/media/|`:
228-
229-
```caddyfile
230-
...
231-
# Matches requests for HTML documents, for static files and for Next.js files,
232-
# except for known API paths and paths with extensions handled by API Platform
233-
@pwa expression `(
234-
{header.Accept}.matches("\\btext/html\\b")
235-
&& !{path}.matches("(?i)(?:^/docs|^/graphql|^/bundles/|^/media/|^/_profiler|^/_wdt|\\.(?:json|html$|csv$|ya?ml$|xml$))")
236-
...
228+
You will need to modify your `Caddyfile` to allow the above `contentUrl` to be accessed directly. If you followed the above configuration for the VichUploaderBundle, that will be in `api/public/media`. Add your folder to the list of path matches, e.g. `|^/media/|`:
229+
230+
<!-- markdownlint-disable no-hard-tabs -->
231+
```patch
232+
# Matches requests for HTML documents, for static files and for Next.js files,
233+
# except for known API paths and paths with extensions handled by API Platform
234+
@pwa expression `(
235+
header({'Accept': '*text/html*'})
236+
&& !path(
237+
- '/docs*', '/graphql*', '/bundles*', '/media*', '/contexts*', '/_profiler*', '/_wdt*',
238+
+ '/media*', '/docs*', '/graphql*', '/bundles*', '/media*', '/contexts*', '/_profiler*', '/_wdt*',
239+
'*.json*', '*.html', '*.csv', '*.yml', '*.yaml', '*.xml'
240+
)
241+
)
242+
|| path('/favicon.ico', '/manifest.json', '/robots.txt', '/_next*', '/sitemap*')`
237243
```
244+
<!-- markdownlint-enable no-hard-tabs -->
238245

239246
### Linking a MediaObject Resource to Another Resource
240247

@@ -246,6 +253,7 @@ We first need to edit our Book resource, and add a new property called `image`.
246253
```php
247254
<?php
248255
// api/src/Entity/Book.php
256+
249257
namespace App\Entity;
250258

251259
use ApiPlatform\Metadata\ApiResource;
@@ -406,11 +414,10 @@ final class MultipartDecoder implements DecoderInterface
406414
{
407415
public const FORMAT = 'multipart';
408416

409-
public function __construct(private RequestStack $requestStack) {}
417+
public function __construct(private RequestStack $requestStack)
418+
{
419+
}
410420

411-
/**
412-
* {@inheritdoc}
413-
*/
414421
public function decode(string $data, string $format, array $context = []): ?array
415422
{
416423
$request = $this->requestStack->getCurrentRequest();
@@ -427,9 +434,6 @@ final class MultipartDecoder implements DecoderInterface
427434
}, $request->request->all()) + $request->files->all();
428435
}
429436

430-
/**
431-
* {@inheritdoc}
432-
*/
433437
public function supportsDecoding(string $format): bool
434438
{
435439
return self::FORMAT === $format;
@@ -452,17 +456,11 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
452456

453457
final class UploadedFileDenormalizer implements DenormalizerInterface
454458
{
455-
/**
456-
* {@inheritdoc}
457-
*/
458459
public function denormalize($data, string $type, string $format = null, array $context = []): UploadedFile
459460
{
460461
return $data;
461462
}
462463

463-
/**
464-
* {@inheritdoc}
465-
*/
466464
public function supportsDenormalization($data, $type, $format = null): bool
467465
{
468466
return $data instanceof UploadedFile;

core/filters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ services:
13311331
# This whole definition can be omitted if automatic service loading is enabled
13321332
'App\Filter\RegexpFilter':
13331333
# The "arguments" key can be omitted if the autowiring is enabled
1334-
arguments: [ '@doctrine', ~, '@?logger' ]
1334+
arguments: [ '@doctrine', '@?logger' ]
13351335
# The "tags" key can be omitted if the autoconfiguration is enabled
13361336
tags: [ 'api_platform.filter' ]
13371337
```
@@ -1343,7 +1343,7 @@ it can also be enabled for some properties:
13431343
# api/config/services.yaml
13441344
services:
13451345
'App\Filter\RegexpFilter':
1346-
arguments: [ '@doctrine', ~, '@?logger', { email: ~, anOtherProperty: ~ } ]
1346+
arguments: [ '@doctrine', '@?logger', { email: ~, anOtherProperty: ~ } ]
13471347
tags: [ 'api_platform.filter' ]
13481348
```
13491349

core/graphql.md

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,6 @@ final class WriteStage implements WriteStageInterface
888888
$this->writeStage = $writeStage;
889889
}
890890
891-
/**
892-
* {@inheritdoc}
893-
*/
894891
public function __invoke($data, string $resourceClass, string $operationName, array $context)
895892
{
896893
// You can add pre-write code here.
@@ -2192,9 +2189,6 @@ final class ErrorHandler implements ErrorHandlerInterface
21922189
$this->defaultErrorHandler = $defaultErrorHandler;
21932190
}
21942191
2195-
/**
2196-
* {@inheritdoc}
2197-
*/
21982192
public function __invoke(array $errors, callable $formatter): array
21992193
{
22002194
// Log or filter the errors.
@@ -2285,9 +2279,6 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
22852279
22862280
final class MyExceptionNormalizer implements NormalizerInterface
22872281
{
2288-
/**
2289-
* {@inheritdoc}
2290-
*/
22912282
public function normalize($object, $format = null, array $context = []): array
22922283
{
22932284
$exception = $object->getPrevious();
@@ -2299,9 +2290,6 @@ final class MyExceptionNormalizer implements NormalizerInterface
22992290
return $error;
23002291
}
23012292
2302-
/**
2303-
* {@inheritdoc}
2304-
*/
23052293
public function supportsNormalization($data, $format = null): bool
23062294
{
23072295
return $data instanceof Error && $data->getPrevious() instanceof MyException;
@@ -2486,9 +2474,6 @@ final class DateTimeType extends ScalarType implements TypeInterface
24862474
return $this->name;
24872475
}
24882476

2489-
/**
2490-
* {@inheritdoc}
2491-
*/
24922477
public function serialize($value)
24932478
{
24942479
// Already serialized.
@@ -2503,10 +2488,7 @@ final class DateTimeType extends ScalarType implements TypeInterface
25032488
return $value->format(\DateTime::ATOM);
25042489
}
25052490

2506-
/**
2507-
* {@inheritdoc}
2508-
*/
2509-
public function parseValue($value)
2491+
public function parseValue($value)
25102492
{
25112493
if (!\is_string($value)) {
25122494
throw new Error(sprintf('DateTime cannot represent non string value: %s', Utils::printSafeJson($value)));
@@ -2520,9 +2502,6 @@ final class DateTimeType extends ScalarType implements TypeInterface
25202502
return $value;
25212503
}
25222504

2523-
/**
2524-
* {@inheritdoc}
2525-
*/
25262505
public function parseLiteral($valueNode, ?array $variables = null)
25272506
{
25282507
if ($valueNode instanceof StringValueNode && false !== \DateTime::createFromFormat(\DateTime::ATOM, $valueNode->value)) {
@@ -2593,9 +2572,6 @@ final class TypeConverter implements TypeConverterInterface
25932572
$this->defaultTypeConverter = $defaultTypeConverter;
25942573
}
25952574
2596-
/**
2597-
* {@inheritdoc}
2598-
*/
25992575
public function convertType(Type $type, bool $input, Operation $rootOperation, string $resourceClass, string $rootResource, ?string $property, int $depth)
26002576
{
26012577
if ('publicationDate' === $property
@@ -2607,9 +2583,6 @@ final class TypeConverter implements TypeConverterInterface
26072583
return $this->defaultTypeConverter->convertType($type, $input, $rootOperation, $resourceClass, $rootResource, $property, $depth);
26082584
}
26092585
2610-
/**
2611-
* {@inheritdoc}
2612-
*/
26132586
public function resolveType(string $type): ?GraphQLType
26142587
{
26152588
return $this->defaultTypeConverter->resolveType($type);
@@ -2822,7 +2795,7 @@ and for an example implementation for the Apollo client check out [Apollo Upload
28222795

28232796
```graphql
28242797
mutation CreateMediaObject($file: Upload!) {
2825-
createMediaObject(input: {file: $file}) {
2798+
uploadMediaObject(input: {file: $file}) {
28262799
mediaObject {
28272800
id
28282801
contentUrl

core/identifiers.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Let's create a `Provider` for the `Person` entity:
6363

6464
```php
6565
<?php
66+
// api/src/State/PersonProvider.php
6667
namespace App\State;
6768

6869
use App\Entity\Person;
@@ -71,9 +72,6 @@ use App\Uuid;
7172

7273
final class PersonProvider implements ProviderInterface
7374
{
74-
/**
75-
* {@inheritDoc}
76-
*/
7775
public function provide(Operation $operation, array $uriVariables = [], array $context = [])
7876
{
7977
// Our identifier is:
@@ -89,6 +87,7 @@ This case is covered by an URI variable transformer:
8987

9088
```php
9189
<?php
90+
// api/src/Identifier/UuidUriVariableTransformer.php
9291
namespace App\Identifier;
9392

9493
use ApiPlatform\Api\UriVariableTransformerInterface;

core/serialization.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,19 +594,13 @@ class PlainIdentifierDenormalizer implements ContextAwareDenormalizerInterface,
594594
$this->iriConverter = $iriConverter;
595595
}
596596
597-
/**
598-
* {@inheritdoc}
599-
*/
600597
public function denormalize($data, $class, $format = null, array $context = [])
601598
{
602599
$data['relatedDummy'] = $this->iriConverter->getIriFromResource(resource: RelatedDummy::class, context: ['uri_variables' => ['id' => $data['relatedDummy']]]);
603600
604601
return $this->denormalizer->denormalize($data, $class, $format, $context + [__CLASS__ => true]);
605602
}
606603
607-
/**
608-
* {@inheritdoc}
609-
*/
610604
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
611605
{
612606
return \in_array($format, ['json', 'jsonld'], true) && is_a($type, Dummy::class, true) && !empty($data['relatedDummy']) && !isset($context[__CLASS__]);
@@ -624,6 +618,7 @@ For instance:
624618
```php
625619
<?php
626620
// api/src/Entity/Book.php
621+
627622
namespace App\Entity;
628623
629624
use ApiPlatform\Metadata\ApiResource;
@@ -657,6 +652,7 @@ It's also possible to only change the denormalization or normalization context:
657652
```php
658653
<?php
659654
// api/src/Entity/Book.php
655+
660656
namespace App\Entity;
661657
662658
use ApiPlatform\Metadata\ApiResource;
@@ -679,6 +675,7 @@ Groups are also supported:
679675
```php
680676
<?php
681677
// api/src/Entity/Book.php
678+
682679
namespace App\Entity;
683680
684681
use ApiPlatform\Metadata\ApiResource;
@@ -711,6 +708,7 @@ Sometimes you need to expose calculated fields. This can be done by leveraging t
711708
```php
712709
<?php
713710
// api/src/Entity/Greeting.php
711+
714712
namespace App\Entity;
715713
716714
use ApiPlatform\Metadata\ApiResource;

core/state-processors.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Here is an implementation example:
3333

3434
```php
3535
<?php
36+
// api/src/State/BlogPostProcessor.php
3637

3738
namespace App\State;
3839

@@ -42,9 +43,6 @@ use ApiPlatform\State\ProcessorInterface;
4243

4344
class BlogPostProcessor implements ProcessorInterface
4445
{
45-
/**
46-
* {@inheritDoc}
47-
*/
4846
public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
4947
{
5048
// call your persistence layer to save $data
@@ -57,6 +55,7 @@ We then configure our operation to use this processor:
5755

5856
```php
5957
<?php
58+
// api/src/Entity/BlogPost.php
6059

6160
namespace App\Entity;
6261

@@ -74,6 +73,7 @@ Otherwise, if you use a custom dependency injection configuration, you need to r
7473

7574
```yaml
7675
# api/config/services.yaml
76+
7777
services:
7878
# ...
7979
App\State\BlogPostProcessor: ~
@@ -91,6 +91,7 @@ Here is an implementation example which sends new users a welcome email after a
9191

9292
```php
9393
<?php
94+
// api/src/Sate/UserProcessor.php
9495

9596
namespace App\State;
9697

@@ -129,6 +130,7 @@ Even with service autowiring and autoconfiguration enabled, you must still confi
129130

130131
```yaml
131132
# api/config/services.yaml
133+
132134
services:
133135
# ...
134136
App\State\UserProcessor:
@@ -147,6 +149,7 @@ And configure that you want to use this processor on the User resource:
147149

148150
```php
149151
<?php
152+
// api/src/Entity/User.php
150153

151154
namespace App\Entity;
152155

0 commit comments

Comments
 (0)