Skip to content

Commit

Permalink
fix(symfony): check operations parameters (#5513)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zowac authored Mar 31, 2023
1 parent 05b5722 commit 871824c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Symfony/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use ApiPlatform\Exception\FilterValidationException;
use ApiPlatform\Exception\InvalidArgumentException;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -558,10 +560,9 @@ private function addDefaultsSection(ArrayNodeDefinition $rootNode): void
return $normalizedDefaults;
});

$reflection = new \ReflectionClass(ApiResource::class);
foreach ($reflection->getConstructor()->getParameters() as $parameter) {
$defaultsNode->children()->variableNode($nameConverter->normalize($parameter->getName()));
}
$this->defineDefault($defaultsNode, new \ReflectionClass(ApiResource::class), $nameConverter);
$this->defineDefault($defaultsNode, new \ReflectionClass(Put::class), $nameConverter);
$this->defineDefault($defaultsNode, new \ReflectionClass(Post::class), $nameConverter);
}

private function addMakerSection(ArrayNodeDefinition $rootNode): void
Expand All @@ -573,4 +574,11 @@ private function addMakerSection(ArrayNodeDefinition $rootNode): void
->end()
->end();
}

private function defineDefault(ArrayNodeDefinition $defaultsNode, \ReflectionClass $reflectionClass, CamelCaseToSnakeCaseNameConverter $nameConverter)
{
foreach ($reflectionClass->getConstructor()->getParameters() as $parameter) {
$defaultsNode->children()->variableNode($nameConverter->normalize($parameter->getName()));
}
}
}

0 comments on commit 871824c

Please sign in to comment.