Skip to content

Commit a504e76

Browse files
committed
fix: attributes parameter order
1 parent dc8a4d2 commit a504e76

15 files changed

+29
-19
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Be sure to add only **your modified files**. If any other file is fixed by cs to
5656

5757
API Platform is following the [Symfony Backward Compatibility Promise](https://symfony.com/doc/current/contributing/code/bc.html).
5858

59+
As users need to use named arguments when using our attributes, they don't follow the backward compatibility rules applied to the constructor.
60+
5961
When you are making a change, make sure no BC break is added.
6062

6163
### Deprecating Code

src/Elasticsearch/State/CollectionProvider.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5959
$limit = $body['size'] ??= $this->pagination->getLimit($operation, $context);
6060
$offset = $body['from'] ??= $this->pagination->getOffset($operation, $context);
6161

62-
$index = Inflector::tableize($operation->getShortName());
63-
$options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $index);
62+
$options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $this->getIndex());
6463

6564
// TODO: remove in 4.x
6665
if ($operation->getElasticsearch() && !$operation->getStateOptions()) {
6766
$options = $this->convertDocumentMetadata($this->documentMetadataFactory->create($resourceClass));
6867
}
6968

7069
$params = [
71-
'index' => $options->getIndex() ?? $index,
70+
'index' => $options->getIndex() ?? $this->getIndex(),
7271
'body' => $body,
7372
];
7473

@@ -92,4 +91,9 @@ private function convertDocumentMetadata(DocumentMetadata $documentMetadata): Op
9291
{
9392
return new Options($documentMetadata->getIndex(), $documentMetadata->getType());
9493
}
94+
95+
private function getIndex(Operation $operation): string
96+
{
97+
return Inflector::tableize($operation->getShortName());
98+
}
9599
}

src/Elasticsearch/State/ItemProvider.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public function __construct(private readonly Client $client, private readonly Do
4242
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
4343
{
4444
$resourceClass = $operation->getClass();
45-
$index = Inflector::tableize($operation->getShortName());
4645

47-
$options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $index);
46+
$options = $operation->getStateOptions() instanceof Options ? $operation->getStateOptions() : new Options(index: $this->getIndex($operation));
4847

4948
// TODO: remove in 4.x
5049
if ($operation->getElasticsearch() && !$operation->getStateOptions()) {
@@ -53,7 +52,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5352

5453
$params = [
5554
'client' => ['ignore' => 404],
56-
'index' => $options->getIndex() ?? $index,
55+
'index' => $options->getIndex() ?? $this->getIndex($operation),
5756
'id' => (string) reset($uriVariables),
5857
];
5958

@@ -78,4 +77,9 @@ private function convertDocumentMetadata(DocumentMetadata $documentMetadata): Op
7877
{
7978
return new Options($documentMetadata->getIndex(), $documentMetadata->getType());
8079
}
80+
81+
private function getIndex(Operation $operation): string
82+
{
83+
return Inflector::tableize($operation->getShortName());
84+
}
8185
}

src/Metadata/ApiResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ public function __construct(
148148
protected ?array $graphQlOperations = null,
149149
$provider = null,
150150
$processor = null,
151-
protected array $extraProperties = [],
152151
protected ?OptionsInterface $stateOptions = null,
152+
protected array $extraProperties = [],
153153
) {
154154
$this->operations = null === $operations ? null : new Operations($operations);
155155
$this->provider = $provider;

src/Metadata/Get.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public function __construct(
9494
?string $name = null,
9595
$provider = null,
9696
$processor = null,
97-
array $extraProperties = [],
9897
?OptionsInterface $stateOptions = null,
98+
array $extraProperties = [],
9999
) {
100100
parent::__construct(self::METHOD_GET, ...\func_get_args());
101101
}

src/Metadata/GetCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ public function __construct(
9696
?string $name = null,
9797
$provider = null,
9898
$processor = null,
99-
array $extraProperties = [],
10099
?string $itemUriTemplate = null,
101100
?OptionsInterface $stateOptions = null,
101+
array $extraProperties = [],
102102
) {
103-
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);
103+
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);
104104
$this->itemUriTemplate = $itemUriTemplate;
105105
}
106106

src/Metadata/GraphQl/DeleteMutation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function __construct(
7171
?string $name = null,
7272
$provider = null,
7373
$processor = null,
74-
array $extraProperties = [],
7574
protected ?OptionsInterface $stateOptions = null,
75+
array $extraProperties = [],
7676
) {
7777
parent::__construct(...\func_get_args());
7878
}

src/Metadata/GraphQl/Operation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public function __construct(
7575
?string $name = null,
7676
?string $provider = null,
7777
?string $processor = null,
78-
array $extraProperties = [],
7978
protected ?OptionsInterface $stateOptions = null,
79+
array $extraProperties = [],
8080
) {
8181
// Abstract operation properties
8282
$this->shortName = $shortName;

src/Metadata/GraphQl/QueryCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function __construct(
7171
?string $name = null,
7272
$provider = null,
7373
$processor = null,
74-
array $extraProperties = [],
7574
protected ?OptionsInterface $stateOptions = null,
75+
array $extraProperties = [],
7676

7777
protected ?bool $nested = null,
7878
) {

src/Metadata/GraphQl/Subscription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public function __construct(
7070
?string $name = null,
7171
$provider = null,
7272
$processor = null,
73-
array $extraProperties = [],
7473
protected ?OptionsInterface $stateOptions = null,
74+
array $extraProperties = [],
7575
) {
7676
parent::__construct(...\func_get_args());
7777
$this->name = $name ?: 'update_subscription';

src/Metadata/HttpOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ public function __construct(
147147
?string $name = null,
148148
$provider = null,
149149
$processor = null,
150-
array $extraProperties = [],
151150
?OptionsInterface $stateOptions = null,
151+
array $extraProperties = [],
152152
) {
153153
$this->shortName = $shortName;
154154
$this->description = $description;

src/Metadata/Operation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public function __construct(
9292
protected ?string $name = null,
9393
$provider = null,
9494
$processor = null,
95-
protected array $extraProperties = [],
9695
protected ?OptionsInterface $stateOptions = null,
96+
protected array $extraProperties = [],
9797
) {
9898
$this->input = $input;
9999
$this->output = $output;

src/Metadata/Patch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public function __construct(
9595
?string $name = null,
9696
$provider = null,
9797
$processor = null,
98-
array $extraProperties = [],
9998
?OptionsInterface $stateOptions = null,
99+
array $extraProperties = [],
100100
) {
101101
parent::__construct(self::METHOD_PATCH, ...\func_get_args());
102102
}

src/Metadata/Post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public function __construct(
9898
$provider = null,
9999
$processor = null,
100100
array $extraProperties = [],
101-
?string $itemUriTemplate = null,
102101
?OptionsInterface $stateOptions = null,
102+
?string $itemUriTemplate = null,
103103
) {
104104
parent::__construct(self::METHOD_POST, ...\func_get_args());
105105
$this->itemUriTemplate = $itemUriTemplate;

src/Metadata/Put.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public function __construct(
9595
?string $name = null,
9696
$provider = null,
9797
$processor = null,
98-
array $extraProperties = [],
9998
?OptionsInterface $stateOptions = null,
99+
array $extraProperties = [],
100100
) {
101101
parent::__construct(self::METHOD_PUT, ...\func_get_args());
102102
}

0 commit comments

Comments
 (0)