Skip to content

Commit ba88c0c

Browse files
[BUG] Do not rely on api-platform/core attributes classes but on interfaces instead (#4785)
* fix: do not rely on api-platform/core attributes classes but on interfaces instead * fix: use HttpOperation::METHOD_POST === ->getMethod() instead of PostOperationInterface
1 parent 171ab42 commit ba88c0c

File tree

7 files changed

+6
-11
lines changed

7 files changed

+6
-11
lines changed

src/Core/Bridge/Symfony/Bundle/Test/Constraint/ArraySubsetTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Constraint;
1515

16-
use PHPUnit\Framework\Constraint\Constraint;
1716
use PHPUnit\SebastianBergmann\Comparator\ComparisonFailure;
1817

1918
/**

src/Hydra/Serializer/DocumentationNormalizer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
use ApiPlatform\Metadata\CollectionOperationInterface;
3232
use ApiPlatform\Metadata\HttpOperation;
3333
use ApiPlatform\Metadata\Operation;
34-
use ApiPlatform\Metadata\Post;
3534
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
3635
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
3736
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
@@ -353,7 +352,7 @@ private function getHydraOperations(string $resourceClass, $resourceMetadata, st
353352
$hydraOperations = [];
354353
foreach ($resourceMetadataCollection as $resourceMetadata) {
355354
foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
356-
if (($operation instanceof Post || $operation instanceof CollectionOperationInterface) !== $collection) {
355+
if ((HttpOperation::METHOD_POST === $operation->getMethod() || $operation instanceof CollectionOperationInterface) !== $collection) {
357356
continue;
358357
}
359358

src/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private function getOperationWithDefaults(ApiResource $resource, Operation $oper
226226
}
227227

228228
return [
229-
sprintf('_api_%s_%s%s', $operation->getUriTemplate() ?: $operation->getShortName(), strtolower($operation->getMethod() ?? HttpOperation::METHOD_GET), $operation instanceof GetCollection ? '_collection' : ''),
229+
sprintf('_api_%s_%s%s', $operation->getUriTemplate() ?: $operation->getShortName(), strtolower($operation->getMethod() ?? HttpOperation::METHOD_GET), $operation instanceof CollectionOperationInterface ? '_collection' : ''),
230230
$operation,
231231
];
232232
}

src/Metadata/Resource/Factory/UriTemplateResourceMetadataCollectionFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use ApiPlatform\Metadata\HttpOperation;
1919
use ApiPlatform\Metadata\Link;
2020
use ApiPlatform\Metadata\Operations;
21-
use ApiPlatform\Metadata\Post;
2221
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
2322
use ApiPlatform\Operation\PathSegmentNameGeneratorInterface;
2423
use Symfony\Component\Routing\Route;
@@ -137,7 +136,7 @@ private function configureUriVariables($operation)
137136
$operation = $this->normalizeUriVariables($operation);
138137

139138
if (!($uriTemplate = $operation->getUriTemplate())) {
140-
if ($operation instanceof Post) {
139+
if ($operation instanceof HttpOperation && HttpOperation::METHOD_POST === $operation->getMethod()) {
141140
return $operation->withUriVariables([]);
142141
}
143142

src/OpenApi/Factory/OpenApiFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use ApiPlatform\Metadata\CollectionOperationInterface;
2424
use ApiPlatform\Metadata\HttpOperation;
2525
use ApiPlatform\Metadata\Operation;
26-
use ApiPlatform\Metadata\Post;
2726
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2827
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
2928
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
@@ -239,7 +238,7 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
239238
break;
240239
}
241240

242-
if (!$operation instanceof CollectionOperationInterface && !$operation instanceof Post) {
241+
if (!$operation instanceof CollectionOperationInterface && HttpOperation::METHOD_POST !== $operation->getMethod()) {
243242
$responses['404'] = new Model\Response('Resource not found');
244243
}
245244

src/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
namespace ApiPlatform\Symfony\Bundle\DependencyInjection;
1515

1616
use ApiPlatform\Core\Annotation\ApiResource as LegacyApiResource;
17-
use ApiPlatform\Metadata\ApiResource;
1817
use ApiPlatform\Doctrine\Common\Filter\OrderFilterInterface;
1918
use ApiPlatform\Elasticsearch\Metadata\Document\DocumentMetadata;
2019
use ApiPlatform\Exception\FilterValidationException;
2120
use ApiPlatform\Exception\InvalidArgumentException;
21+
use ApiPlatform\Metadata\ApiResource;
2222
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
2323
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
2424
use Doctrine\ORM\EntityManagerInterface;

src/Symfony/Routing/IriConverter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use ApiPlatform\Metadata\GetCollection;
2929
use ApiPlatform\Metadata\HttpOperation;
3030
use ApiPlatform\Metadata\Operation;
31-
use ApiPlatform\Metadata\Post;
3231
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
3332
use ApiPlatform\State\ProviderInterface;
3433
use ApiPlatform\State\UriVariablesResolverTrait;
@@ -138,7 +137,7 @@ public function getIriFromResource($item, int $referenceType = UrlGeneratorInter
138137
// In symfony the operation name is the route name, try to find one if none provided
139138
if (
140139
!$operation->getName()
141-
|| $operation instanceof Post
140+
|| ($operation instanceof HttpOperation && HttpOperation::METHOD_POST === $operation->getMethod())
142141
|| $isLegacySubresource
143142
|| $isLegacyCustomResource
144143
) {

0 commit comments

Comments
 (0)