Skip to content

Commit

Permalink
fix: attributes parameter order (#5317)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka authored Jan 11, 2023
1 parent dc8a4d2 commit 9f5a408
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/Elasticsearch/State/CollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ 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()) {
$options = $this->convertDocumentMetadata($this->documentMetadataFactory->create($resourceClass));
}

$params = [
'index' => $options->getIndex() ?? $index,
'index' => $options->getIndex() ?? $this->getIndex($operation),
'body' => $body,
];

Expand All @@ -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());
}
}
10 changes: 7 additions & 3 deletions src/Elasticsearch/State/ItemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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),
];

Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion src/Metadata/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Metadata/GetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/GraphQl/DeleteMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/GraphQl/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/GraphQl/QueryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/GraphQl/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/HttpOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 9f5a408

Please sign in to comment.