Skip to content

Commit 9720364

Browse files
chore: update api-platform/core to 3.3.3 (#405)
1 parent cdfef83 commit 9720364

26 files changed

+75
-585
lines changed

api/.php-cs-fixer.dist.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
'phpdoc_to_comment' => false,
3434
'void_return' => true,
3535
'concat_space' => ['spacing' => 'one'],
36-
'braces' => ['allow_single_line_closure' => true],
3736
'nullable_type_declaration' => true,
3837
])
3938
->setFinder($finder)

api/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"php": ">=8.3",
66
"ext-ctype": "*",
77
"ext-iconv": "*",
8-
"api-platform/core": "^3.3.0@beta",
8+
"api-platform/core": "^3.3",
99
"doctrine/common": "^3.4",
1010
"doctrine/doctrine-bundle": "^2.11",
1111
"doctrine/doctrine-fixtures-bundle": "^3.5",

api/composer.lock

Lines changed: 9 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/config/packages/api_platform.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
api_platform:
22
title: API Platform's demo
3-
version: 3.3.0
3+
version: 3.3.3
44
description: |
55
This is a demo application of the [API Platform](https://api-platform.com) framework.
66
[Its source code](https://github.com/api-platform/demo) includes various examples, check it out!

api/src/Doctrine/Orm/Filter/NameFilter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
88
use ApiPlatform\Doctrine\Orm\PropertyHelperTrait;
99
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
10-
use ApiPlatform\Exception\InvalidArgumentException;
1110
use ApiPlatform\Metadata\Operation;
1211
use Doctrine\ORM\QueryBuilder;
1312

@@ -73,7 +72,7 @@ protected function normalizeValues($value, string $property): ?array
7372

7473
if (empty($values)) {
7574
$this->getLogger()->notice('Invalid filter ignored', [
76-
'exception' => new InvalidArgumentException(sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
75+
'exception' => new \InvalidArgumentException(sprintf('At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format', $property)),
7776
]);
7877

7978
return null;

api/src/Entity/Book.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
use ApiPlatform\Metadata\GetCollection;
1616
use ApiPlatform\Metadata\Post;
1717
use ApiPlatform\Metadata\Put;
18+
use ApiPlatform\Metadata\UrlGeneratorInterface;
1819
use App\Enum\BookCondition;
1920
use App\Repository\BookRepository;
2021
use App\State\Processor\BookPersistProcessor;
2122
use App\State\Processor\BookRemoveProcessor;
23+
use Doctrine\Common\Collections\ArrayCollection;
24+
use Doctrine\Common\Collections\Collection;
2225
use Doctrine\DBAL\Types\Types;
2326
use Doctrine\ORM\Mapping as ORM;
2427
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
@@ -44,7 +47,6 @@
4447
paginationClientItemsPerPage: true
4548
),
4649
new Post(
47-
// Mercure publish is done manually in MercureProcessor through BookPersistProcessor
4850
processor: BookPersistProcessor::class,
4951
itemUriTemplate: '/admin/books/{id}{._format}'
5052
),
@@ -54,12 +56,10 @@
5456
// https://github.com/api-platform/admin/issues/370
5557
new Put(
5658
uriTemplate: '/admin/books/{id}{._format}',
57-
// Mercure publish is done manually in MercureProcessor through BookPersistProcessor
5859
processor: BookPersistProcessor::class
5960
),
6061
new Delete(
6162
uriTemplate: '/admin/books/{id}{._format}',
62-
// Mercure publish is done manually in MercureProcessor through BookRemoveProcessor
6363
processor: BookRemoveProcessor::class
6464
),
6565
],
@@ -71,7 +71,13 @@
7171
AbstractNormalizer::GROUPS => ['Book:write'],
7272
],
7373
collectDenormalizationErrors: true,
74-
security: 'is_granted("OIDC_ADMIN")'
74+
security: 'is_granted("OIDC_ADMIN")',
75+
mercure: [
76+
'topics' => [
77+
'@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/admin/books/{id}{._format}"))',
78+
'@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/books/{id}{._format}"))',
79+
],
80+
]
7581
)]
7682
#[ApiResource(
7783
types: ['https://schema.org/Book', 'https://schema.org/Offer'],
@@ -155,14 +161,18 @@ class Book
155161
/**
156162
* An IRI of reviews.
157163
*
164+
* @var Collection<int, Review>
165+
*
158166
* @see https://schema.org/reviews
159167
*/
160168
#[ApiProperty(
161169
types: ['https://schema.org/reviews'],
162-
example: '/books/6acacc80-8321-4d83-9b02-7f2c7bf6eb1d/reviews'
170+
example: '/books/6acacc80-8321-4d83-9b02-7f2c7bf6eb1d/reviews',
171+
uriTemplate: '/books/{bookId}/reviews{._format}'
163172
)]
164173
#[Groups(groups: ['Book:read', 'Bookmark:read'])]
165-
public ?string $reviews = null;
174+
#[ORM\OneToMany(targetEntity: Review::class, mappedBy: 'book')]
175+
public Collection $reviews;
166176

167177
/**
168178
* The overall rating, based on a collection of reviews or ratings, of the item.
@@ -176,6 +186,11 @@ class Book
176186
#[Groups(groups: ['Book:read', 'Book:read:admin', 'Bookmark:read'])]
177187
public ?int $rating = null;
178188

189+
public function __construct()
190+
{
191+
$this->reviews = new ArrayCollection();
192+
}
193+
179194
public function getId(): ?Uuid
180195
{
181196
return $this->id;

api/src/Entity/Review.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use ApiPlatform\Metadata\Patch;
1515
use ApiPlatform\Metadata\Post;
1616
use ApiPlatform\Metadata\Put;
17+
use ApiPlatform\Metadata\UrlGeneratorInterface;
1718
use ApiPlatform\State\CreateProvider;
1819
use App\Repository\ReviewRepository;
1920
use App\Security\Voter\OidcTokenPermissionVoter;
@@ -56,12 +57,10 @@
5657
// https://github.com/api-platform/admin/issues/370
5758
new Put(
5859
uriTemplate: '/admin/reviews/{id}{._format}',
59-
// Mercure publish is done manually in MercureProcessor through ReviewPersistProcessor
6060
processor: ReviewPersistProcessor::class
6161
),
6262
new Delete(
6363
uriTemplate: '/admin/reviews/{id}{._format}',
64-
// Mercure publish is done manually in MercureProcessor through ReviewRemoveProcessor
6564
processor: ReviewRemoveProcessor::class
6665
),
6766
],
@@ -77,7 +76,13 @@
7776
AbstractNormalizer::GROUPS => ['Review:write', 'Review:write:admin'],
7877
],
7978
collectDenormalizationErrors: true,
80-
security: 'is_granted("OIDC_ADMIN")'
79+
security: 'is_granted("OIDC_ADMIN")',
80+
mercure: [
81+
'topics' => [
82+
'@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/admin/reviews/{id}{._format}"))',
83+
'@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/books/{bookId}/reviews/{id}{._format}"))',
84+
],
85+
]
8186
)]
8287
#[ApiResource(
8388
types: ['https://schema.org/Review'],
@@ -100,7 +105,6 @@
100105
),
101106
new Post(
102107
security: 'is_granted("OIDC_USER")',
103-
// Mercure publish is done manually in MercureProcessor through ReviewPersistProcessor
104108
processor: ReviewPersistProcessor::class,
105109
provider: CreateProvider::class,
106110
itemUriTemplate: '/books/{bookId}/reviews/{id}{._format}',
@@ -114,7 +118,6 @@
114118
],
115119
/** @see OidcTokenPermissionVoter */
116120
security: 'is_granted("OIDC_USER", request.getRequestUri())',
117-
// Mercure publish is done manually in MercureProcessor through ReviewPersistProcessor
118121
processor: ReviewPersistProcessor::class
119122
),
120123
new Delete(
@@ -125,7 +128,6 @@
125128
],
126129
/** @see OidcTokenPermissionVoter */
127130
security: 'is_granted("OIDC_USER", request.getRequestUri())',
128-
// Mercure publish is done manually in MercureProcessor through ReviewRemoveProcessor
129131
processor: ReviewRemoveProcessor::class
130132
),
131133
],
@@ -172,7 +174,7 @@ class Review
172174
#[ApiProperty(types: ['https://schema.org/itemReviewed'])]
173175
#[Assert\NotNull]
174176
#[Groups(groups: ['Review:read', 'Review:write:admin'])]
175-
#[ORM\ManyToOne(targetEntity: Book::class)]
177+
#[ORM\ManyToOne(targetEntity: Book::class, inversedBy: 'reviews')]
176178
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
177179
public ?Book $book = null;
178180

api/src/Security/Http/Protection/ResourceResourceHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace App\Security\Http\Protection;
66

7-
use ApiPlatform\Api\UrlGeneratorInterface;
87
use ApiPlatform\Metadata\IriConverterInterface;
98
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
9+
use ApiPlatform\Metadata\UrlGeneratorInterface;
1010
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1111
use Symfony\Component\Security\Core\User\UserInterface;
1212
use Symfony\Contracts\HttpClient\HttpClientInterface;

api/src/Serializer/BookNormalizer.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use App\Repository\ReviewRepository;
99
use Doctrine\Persistence\ObjectRepository;
1010
use Symfony\Component\DependencyInjection\Attribute\Autowire;
11-
use Symfony\Component\Routing\RouterInterface;
1211
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
1312
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
1413
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -21,7 +20,6 @@ final class BookNormalizer implements NormalizerInterface, NormalizerAwareInterf
2120
* @param ReviewRepository $repository
2221
*/
2322
public function __construct(
24-
private RouterInterface $router,
2523
#[Autowire(service: ReviewRepository::class)]
2624
private ObjectRepository $repository
2725
) {
@@ -32,9 +30,6 @@ public function __construct(
3230
*/
3331
public function normalize(mixed $object, ?string $format = null, array $context = []): array
3432
{
35-
$object->reviews = $this->router->generate('_api_/books/{bookId}/reviews{._format}_get_collection', [
36-
'bookId' => $object->getId(),
37-
]);
3833
$object->rating = $this->repository->getAverageRating($object);
3934

4035
return $this->normalizer->normalize($object, $format, [self::class => true] + $context);

api/src/Serializer/IriTransformerNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace App\Serializer;
66

7-
use ApiPlatform\Api\IriConverterInterface;
8-
use ApiPlatform\Api\UrlGeneratorInterface;
97
use ApiPlatform\JsonLd\Serializer\ItemNormalizer;
8+
use ApiPlatform\Metadata\IriConverterInterface;
109
use ApiPlatform\Metadata\Operation\Factory\OperationMetadataFactoryInterface;
10+
use ApiPlatform\Metadata\UrlGeneratorInterface;
1111
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
1212
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
1313
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

0 commit comments

Comments
 (0)