Skip to content

Commit 23141d8

Browse files
committed
Merge branch '2.6'
* 2.6: docs: update changelog fix: defaults when using attributes (#3978)
2 parents 27d38a1 + 4b293b0 commit 23141d8

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.6.1
4+
5+
* Fix defaults when using attributes (#3978)
6+
37
## 2.6.0
48

59
* Cache: adds a `max_header_length` configuration (#2865)

src/Metadata/Resource/Factory/AnnotationResourceMetadataFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,15 @@ private function handleNotFound(?ResourceMetadata $parentPropertyMetadata, strin
8888

8989
private function createMetadata(ApiResource $annotation, ResourceMetadata $parentResourceMetadata = null): ResourceMetadata
9090
{
91-
$attributes = (null === $annotation->attributes && [] === $this->defaults['attributes']) ? null : (array) $annotation->attributes + $this->defaults['attributes'];
91+
$attributes = null;
92+
if (null !== $annotation->attributes || [] !== $this->defaults['attributes']) {
93+
$attributes = (array) $annotation->attributes;
94+
foreach ($this->defaults['attributes'] as $key => $value) {
95+
if (!isset($attributes[$key])) {
96+
$attributes[$key] = $value;
97+
}
98+
}
99+
}
92100

93101
if (!$parentResourceMetadata) {
94102
return new ResourceMetadata(

src/Metadata/Resource/Factory/ExtractorResourceMetadataFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ public function create(string $resourceClass): ResourceMetadata
5959
$resource['itemOperations'] = $resource['itemOperations'] ?? $this->defaults['item_operations'] ?? null;
6060
$resource['collectionOperations'] = $resource['collectionOperations'] ?? $this->defaults['collection_operations'] ?? null;
6161
$resource['graphql'] = $resource['graphql'] ?? $this->defaults['graphql'] ?? null;
62-
$resource['attributes'] = (null === $resource['attributes'] && [] === $this->defaults['attributes']) ? null : (array) $resource['attributes'] + $this->defaults['attributes'];
62+
63+
if (null !== $resource['attributes'] || [] !== $this->defaults['attributes']) {
64+
$resource['attributes'] = (array) $resource['attributes'];
65+
foreach ($this->defaults['attributes'] as $key => $value) {
66+
if (!isset($resource['attributes'][$key])) {
67+
$resource['attributes'][$key] = $value;
68+
}
69+
}
70+
}
6371

6472
return $this->update($parentResourceMetadata ?: new ResourceMetadata(), $resource);
6573
}

tests/Metadata/Resource/Factory/AnnotationResourceMetadataFactoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function testCreateWithDefaults()
8080
'attributes' => [
8181
'pagination_client_enabled' => true,
8282
'pagination_maximum_items_per_page' => 10,
83+
'stateless' => null,
8384
],
8485
]);
8586
$reader = $this->prophesize(Reader::class);

tests/Metadata/Resource/Factory/ExtractorResourceMetadataFactoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ public function testItFallbacksToDefaultConfiguration()
312312
'subresourceOperations' => null,
313313
'itemOperations' => ['get', 'delete'],
314314
'attributes' => [
315+
'pagination_items_per_page' => null,
315316
'pagination_maximum_items_per_page' => 10,
316317
'stateless' => false,
317318
],

0 commit comments

Comments
 (0)