diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2ae544ed434..fa907178b11 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,6 +56,8 @@ Be sure to add only **your modified files**. If any other file is fixed by cs to API Platform is following the [Symfony Backward Compatibility Promise](https://symfony.com/doc/current/contributing/code/bc.html). +As users need to use named arguments when using our attributes, they don't follow the backward compatibility rules applied to the constructor. + When you are making a change, make sure no BC break is added. ### Deprecating Code diff --git a/src/Elasticsearch/State/CollectionProvider.php b/src/Elasticsearch/State/CollectionProvider.php index 11a48fb21f3..483978cf7e9 100644 --- a/src/Elasticsearch/State/CollectionProvider.php +++ b/src/Elasticsearch/State/CollectionProvider.php @@ -59,8 +59,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c $limit = $body['size'] ??= $this->pagination->getLimit($operation, $context); $offset = $body['from'] ??= $this->pagination->getOffset($operation, $context); - $index = Inflector::tableize($operation->getShortName()); - $options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $index); + $options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $this->getIndex($operation)); // TODO: remove in 4.x if ($operation->getElasticsearch() && !$operation->getStateOptions()) { @@ -68,7 +67,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c } $params = [ - 'index' => $options->getIndex() ?? $index, + 'index' => $options->getIndex() ?? $this->getIndex($operation), 'body' => $body, ]; @@ -92,4 +91,9 @@ private function convertDocumentMetadata(DocumentMetadata $documentMetadata): Op { return new Options($documentMetadata->getIndex(), $documentMetadata->getType()); } + + private function getIndex(Operation $operation): string + { + return Inflector::tableize($operation->getShortName()); + } } diff --git a/src/Elasticsearch/State/ItemProvider.php b/src/Elasticsearch/State/ItemProvider.php index e2f8bde0004..69be23c1e40 100644 --- a/src/Elasticsearch/State/ItemProvider.php +++ b/src/Elasticsearch/State/ItemProvider.php @@ -42,9 +42,8 @@ public function __construct(private readonly Client $client, private readonly Do public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object { $resourceClass = $operation->getClass(); - $index = Inflector::tableize($operation->getShortName()); - $options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $index); + $options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $this->getIndex($operation)); // TODO: remove in 4.x if ($operation->getElasticsearch() && !$operation->getStateOptions()) { @@ -53,7 +52,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c $params = [ 'client' => ['ignore' => 404], - 'index' => $options->getIndex() ?? $index, + 'index' => $options->getIndex() ?? $this->getIndex($operation), 'id' => (string) reset($uriVariables), ]; @@ -78,4 +77,9 @@ private function convertDocumentMetadata(DocumentMetadata $documentMetadata): Op { return new Options($documentMetadata->getIndex(), $documentMetadata->getType()); } + + private function getIndex(Operation $operation): string + { + return Inflector::tableize($operation->getShortName()); + } } diff --git a/src/Metadata/ApiResource.php b/src/Metadata/ApiResource.php index bc26fc35596..d897c0ed230 100644 --- a/src/Metadata/ApiResource.php +++ b/src/Metadata/ApiResource.php @@ -148,8 +148,8 @@ public function __construct( protected ?array $graphQlOperations = null, $provider = null, $processor = null, - protected array $extraProperties = [], protected ?OptionsInterface $stateOptions = null, + protected array $extraProperties = [], ) { $this->operations = null === $operations ? null : new Operations($operations); $this->provider = $provider; diff --git a/src/Metadata/Get.php b/src/Metadata/Get.php index b1849c4089b..a3f931ca423 100644 --- a/src/Metadata/Get.php +++ b/src/Metadata/Get.php @@ -94,8 +94,8 @@ public function __construct( ?string $name = null, $provider = null, $processor = null, - array $extraProperties = [], ?OptionsInterface $stateOptions = null, + array $extraProperties = [], ) { parent::__construct(self::METHOD_GET, ...\func_get_args()); } diff --git a/src/Metadata/GetCollection.php b/src/Metadata/GetCollection.php index b1ad549c6d9..a9795c50ea8 100644 --- a/src/Metadata/GetCollection.php +++ b/src/Metadata/GetCollection.php @@ -96,11 +96,11 @@ public function __construct( ?string $name = null, $provider = null, $processor = null, - array $extraProperties = [], ?string $itemUriTemplate = null, ?OptionsInterface $stateOptions = null, + array $extraProperties = [], ) { - parent::__construct(self::METHOD_GET, $uriTemplate, $types, $formats, $inputFormats, $outputFormats, $uriVariables, $routePrefix, $routeName, $defaults, $requirements, $options, $stateless, $sunset, $acceptPatch, $status, $host, $schemes, $condition, $controller, $cacheHeaders, $hydraContext, $openapiContext, $openapi, $exceptionToStatus, $queryParameterValidationEnabled, $shortName, $class, $paginationEnabled, $paginationType, $paginationItemsPerPage, $paginationMaximumItemsPerPage, $paginationPartial, $paginationClientEnabled, $paginationClientItemsPerPage, $paginationClientPartial, $paginationFetchJoinCollection, $paginationUseOutputWalkers, $paginationViaCursor, $order, $description, $normalizationContext, $denormalizationContext, $security, $securityMessage, $securityPostDenormalize, $securityPostDenormalizeMessage, $securityPostValidation, $securityPostValidationMessage, $deprecationReason, $filters, $validationContext, $input, $output, $mercure, $messenger, $elasticsearch, $urlGenerationStrategy, $read, $deserialize, $validate, $write, $serialize, $fetchPartial, $forceEager, $priority, $name, $provider, $processor, $extraProperties, $stateOptions); + parent::__construct(self::METHOD_GET, $uriTemplate, $types, $formats, $inputFormats, $outputFormats, $uriVariables, $routePrefix, $routeName, $defaults, $requirements, $options, $stateless, $sunset, $acceptPatch, $status, $host, $schemes, $condition, $controller, $cacheHeaders, $hydraContext, $openapiContext, $openapi, $exceptionToStatus, $queryParameterValidationEnabled, $shortName, $class, $paginationEnabled, $paginationType, $paginationItemsPerPage, $paginationMaximumItemsPerPage, $paginationPartial, $paginationClientEnabled, $paginationClientItemsPerPage, $paginationClientPartial, $paginationFetchJoinCollection, $paginationUseOutputWalkers, $paginationViaCursor, $order, $description, $normalizationContext, $denormalizationContext, $security, $securityMessage, $securityPostDenormalize, $securityPostDenormalizeMessage, $securityPostValidation, $securityPostValidationMessage, $deprecationReason, $filters, $validationContext, $input, $output, $mercure, $messenger, $elasticsearch, $urlGenerationStrategy, $read, $deserialize, $validate, $write, $serialize, $fetchPartial, $forceEager, $priority, $name, $provider, $processor, $stateOptions, $extraProperties); $this->itemUriTemplate = $itemUriTemplate; } diff --git a/src/Metadata/GraphQl/DeleteMutation.php b/src/Metadata/GraphQl/DeleteMutation.php index ffbe788bb48..a37b8112580 100644 --- a/src/Metadata/GraphQl/DeleteMutation.php +++ b/src/Metadata/GraphQl/DeleteMutation.php @@ -71,8 +71,8 @@ public function __construct( ?string $name = null, $provider = null, $processor = null, - array $extraProperties = [], protected ?OptionsInterface $stateOptions = null, + array $extraProperties = [], ) { parent::__construct(...\func_get_args()); } diff --git a/src/Metadata/GraphQl/Operation.php b/src/Metadata/GraphQl/Operation.php index 4a707dceb35..786f4e39794 100644 --- a/src/Metadata/GraphQl/Operation.php +++ b/src/Metadata/GraphQl/Operation.php @@ -75,8 +75,8 @@ public function __construct( ?string $name = null, ?string $provider = null, ?string $processor = null, - array $extraProperties = [], protected ?OptionsInterface $stateOptions = null, + array $extraProperties = [], ) { // Abstract operation properties $this->shortName = $shortName; diff --git a/src/Metadata/GraphQl/QueryCollection.php b/src/Metadata/GraphQl/QueryCollection.php index fbfb4e163e6..4229266bd3c 100644 --- a/src/Metadata/GraphQl/QueryCollection.php +++ b/src/Metadata/GraphQl/QueryCollection.php @@ -71,8 +71,8 @@ public function __construct( ?string $name = null, $provider = null, $processor = null, - array $extraProperties = [], protected ?OptionsInterface $stateOptions = null, + array $extraProperties = [], protected ?bool $nested = null, ) { diff --git a/src/Metadata/GraphQl/Subscription.php b/src/Metadata/GraphQl/Subscription.php index b827d2546ad..252a83ac48f 100644 --- a/src/Metadata/GraphQl/Subscription.php +++ b/src/Metadata/GraphQl/Subscription.php @@ -70,8 +70,8 @@ public function __construct( ?string $name = null, $provider = null, $processor = null, - array $extraProperties = [], protected ?OptionsInterface $stateOptions = null, + array $extraProperties = [], ) { parent::__construct(...\func_get_args()); $this->name = $name ?: 'update_subscription'; diff --git a/src/Metadata/HttpOperation.php b/src/Metadata/HttpOperation.php index e33699eb4de..6eb89ab32d0 100644 --- a/src/Metadata/HttpOperation.php +++ b/src/Metadata/HttpOperation.php @@ -147,8 +147,8 @@ public function __construct( ?string $name = null, $provider = null, $processor = null, - array $extraProperties = [], ?OptionsInterface $stateOptions = null, + array $extraProperties = [], ) { $this->shortName = $shortName; $this->description = $description; diff --git a/src/Metadata/Operation.php b/src/Metadata/Operation.php index 70a8f28ca1c..7d28d539817 100644 --- a/src/Metadata/Operation.php +++ b/src/Metadata/Operation.php @@ -92,8 +92,8 @@ public function __construct( protected ?string $name = null, $provider = null, $processor = null, - protected array $extraProperties = [], protected ?OptionsInterface $stateOptions = null, + protected array $extraProperties = [], ) { $this->input = $input; $this->output = $output; diff --git a/src/Metadata/Patch.php b/src/Metadata/Patch.php index 844dc483e3f..652070c9a66 100644 --- a/src/Metadata/Patch.php +++ b/src/Metadata/Patch.php @@ -95,8 +95,8 @@ public function __construct( ?string $name = null, $provider = null, $processor = null, - array $extraProperties = [], ?OptionsInterface $stateOptions = null, + array $extraProperties = [], ) { parent::__construct(self::METHOD_PATCH, ...\func_get_args()); } diff --git a/src/Metadata/Post.php b/src/Metadata/Post.php index f297599fc43..e908e43cca3 100644 --- a/src/Metadata/Post.php +++ b/src/Metadata/Post.php @@ -98,8 +98,8 @@ public function __construct( $provider = null, $processor = null, array $extraProperties = [], - ?string $itemUriTemplate = null, ?OptionsInterface $stateOptions = null, + ?string $itemUriTemplate = null, ) { parent::__construct(self::METHOD_POST, ...\func_get_args()); $this->itemUriTemplate = $itemUriTemplate; diff --git a/src/Metadata/Put.php b/src/Metadata/Put.php index 2bf889a5c4e..0d14bf3684f 100644 --- a/src/Metadata/Put.php +++ b/src/Metadata/Put.php @@ -95,8 +95,8 @@ public function __construct( ?string $name = null, $provider = null, $processor = null, - array $extraProperties = [], ?OptionsInterface $stateOptions = null, + array $extraProperties = [], ) { parent::__construct(self::METHOD_PUT, ...\func_get_args()); }