Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Hydra/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ private function getHydraOperations(bool $collection, ?ResourceMetadataCollectio
$hydraOperations = [];
foreach ($resourceMetadataCollection as $resourceMetadata) {
foreach ($resourceMetadata->getOperations() as $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

if (true === $operation->getHideHydraOperation()) {
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions src/JsonSchema/ResourceMetadataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ private function findOperationForType(ResourceMetadataCollection $resourceMetada
// Find the operation and use the first one that matches criterias
foreach ($resourceMetadataCollection as $resourceMetadata) {
foreach ($resourceMetadata->getOperations() ?? [] as $op) {
if (!$op instanceof HttpOperation) {
continue;
}

if (!$lookForCollection && $op instanceof CollectionOperationInterface) {
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Metadata/Operation/Factory/OperationMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\Metadata\Operation\Factory;

use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
Expand All @@ -28,6 +29,10 @@ public function create(string $uriTemplate, array $context = []): ?Operation
foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
foreach ($this->resourceMetadataCollectionFactory->create($resourceClass) as $resource) {
foreach ($resource->getOperations() as $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

if ($operation->getUriTemplate() === $uriTemplate || $operation->getName() === $uriTemplate) {
return $operation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace ApiPlatform\Metadata\Resource\Factory;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Operations;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;

Expand Down Expand Up @@ -42,6 +43,10 @@ public function create(string $resourceClass): ResourceMetadataCollection
/** @var ApiResource $resource */
$operations = $resource->getOperations() ?? new Operations();
foreach ($resource->getOperations() as $key => $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

if ($operation->getRouteName() || $operation->getController()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ private function buildResourceOperations(array $metadataCollection, string $reso
private function hasSameOperation(ApiResource $resource, string $operationClass, HttpOperation $operation): bool
{
foreach ($resource->getOperations() ?? [] as $o) {
if (!$o instanceof HttpOperation) {
continue;
}

if ($o instanceof $operationClass && $operation->getUriTemplate() === $o->getUriTemplate() && $operation->getName() === $o->getName() && $operation->getRouteName() === $o->getRouteName()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\Metadata\Resource\Factory;

use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;

/**
Expand Down Expand Up @@ -47,6 +48,10 @@ public function create(string $resourceClass): ResourceMetadataCollection
continue;
}

if (!$operation instanceof HttpOperation) {
continue;
}

if ($operation->getRouteName()) {
$operations->add($operationName, $operation->withName($operation->getRouteName()));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function create(string $resourceClass): ResourceMetadataCollection

$operations = new Operations();
foreach ($resource->getOperations() ?? new Operations() as $key => $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

/** @var HttpOperation */
$operation = $this->configureUriVariables($operation);

Expand Down
5 changes: 5 additions & 0 deletions src/Metadata/Resource/ResourceMetadataCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Metadata\Exception\OperationNotFoundException;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Operation;

/**
Expand Down Expand Up @@ -58,6 +59,10 @@ public function getOperation(?string $operationName = null, bool $forceCollectio

if (!$forceGraphQl) {
foreach ($metadata->getOperations() ?? [] as $name => $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

$isCollection = $operation instanceof CollectionOperationInterface;
$method = $operation->getMethod();
$isGetOperation = 'GET' === $method || 'OPTIONS' === $method || 'HEAD' === $method;
Expand Down
4 changes: 4 additions & 0 deletions src/OpenApi/Factory/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
}

foreach ($resource->getOperations() as $operationName => $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

$resourceShortName = $operation->getShortName() ?? $operation;
// No path to return
if (null === $operation->getUriTemplate() && null === $operation->getRouteName()) {
Expand Down
4 changes: 4 additions & 0 deletions src/State/ErrorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
$resourceCollection = $this->resourceMetadataCollectionFactory->create($operation->getClass());
foreach ($resourceCollection as $resource) {
foreach ($resource->getOperations() as $name => $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

if (isset($operation->getOutputFormats()[$request->getRequestFormat()])) {
$request->attributes->set('_api_operation', $operation);
$request->attributes->set('_api_operation_nme', $name);
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Bundle/Command/DebugResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\Symfony\Bundle\Command;

use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -73,6 +74,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

foreach ($resource->getOperations() as $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

if ($operation->getUriTemplate()) {
$resources[] = ($resource->getRoutePrefix() ?? '').$operation->getUriTemplate();
break;
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/EventListener/ErrorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ class: Error::class,
// TODO: move this to ResourceMetadataCollection?
foreach ($resourceCollection as $resource) {
foreach ($resource->getOperations() as $op) {
if (!$op instanceof HttpOperation) {
continue;
}

foreach ($op->getOutputFormats() ?? [] as $key => $value) {
if ($key === $format) {
$operation = $op;
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Routing/ApiLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace ApiPlatform\Symfony\Routing;

use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
use ApiPlatform\OpenApi\Attributes\Webhook;
Expand Down Expand Up @@ -57,6 +58,10 @@ public function load(mixed $data, ?string $type = null): RouteCollection
foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
foreach ($this->resourceMetadataFactory->create($resourceClass) as $resourceMetadata) {
foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
if (!$operation instanceof HttpOperation) {
continue;
}

if ($operation->getOpenapi() instanceof Webhook) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function create(string $resourceClass): ResourceMetadataCollection
}

// As we deprecate the parameter validator, we declare a parameter for each filter transfering validation to the new system
if (!$operation instanceof HttpOperation) {
continue;
}

if ($operation->getFilters() && 0 === $parameters->count()) {
$parameters = $this->addFilterValidation($operation);
}
Expand Down
Loading