Skip to content

Commit 4c37880

Browse files
committed
Change links format
1 parent 99a05ff commit 4c37880

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/JsonApi/Serializer/CollectionNormalizer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function normalize($object, $format = null, array $context = [])
7070

7171
$resourceClass = $this->resourceClassResolver->getResourceClass($object, $context['resource_class'] ?? null, true);
7272
$context = $this->initContext($resourceClass, $context);
73-
$parsed = IriHelper::parseIri($context['uri'] ?? '/', $this->pageParameterName);
73+
$parsed = IriHelper::parseIri($context['request_uri'] ?? '/', $this->pageParameterName);
7474

7575
$currentPage = $lastPage = $itemsPerPage = $pageTotalItems = null;
7676
if ($paginated = $isPaginator = $object instanceof PartialPaginatorInterface) {
@@ -87,22 +87,22 @@ public function normalize($object, $format = null, array $context = [])
8787
$data = [
8888
'data' => [],
8989
'links' => [
90-
'self' => IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $paginated ? $currentPage : null, true),
90+
'self' => IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $paginated ? $currentPage : null),
9191
],
9292
];
9393

9494
if ($paginated) {
9595
if (null !== $lastPage) {
96-
$data['links']['first'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, 1., true);
97-
$data['links']['last'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $lastPage, true);
96+
$data['links']['first'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, 1.);
97+
$data['links']['last'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $lastPage);
9898
}
9999

100100
if (1. !== $currentPage) {
101-
$data['links']['prev'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $currentPage - 1., true);
101+
$data['links']['prev'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $currentPage - 1.);
102102
}
103103

104104
if (null !== $lastPage && $currentPage !== $lastPage || null === $lastPage && $pageTotalItems >= $itemsPerPage) {
105-
$data['links']['next'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $currentPage + 1., true);
105+
$data['links']['next'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $this->pageParameterName, $currentPage + 1.);
106106
}
107107
}
108108

tests/JsonApi/Serializer/CollectionNormalizerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testNormalizePaginator()
5959
'foo',
6060
CollectionNormalizer::FORMAT,
6161
[
62-
'uri' => 'http://localhost/foos?page=3',
62+
'request_uri' => '/foos?page=3',
6363
'api_sub_level' => true,
6464
'resource_class' => 'Foo',
6565
]
@@ -80,11 +80,11 @@ public function testNormalizePaginator()
8080

8181
$expected = [
8282
'links' => [
83-
'self' => 'http://localhost/foos?page=3',
84-
'first' => 'http://localhost/foos?page=1',
85-
'last' => 'http://localhost/foos?page=7',
86-
'prev' => 'http://localhost/foos?page=2',
87-
'next' => 'http://localhost/foos?page=4',
83+
'self' => '/foos?page=3',
84+
'first' => '/foos?page=1',
85+
'last' => '/foos?page=7',
86+
'prev' => '/foos?page=2',
87+
'next' => '/foos?page=4',
8888
],
8989
'data' => [
9090
[
@@ -103,7 +103,7 @@ public function testNormalizePaginator()
103103
],
104104
];
105105

106-
$this->assertEquals($expected, $normalizer->normalize($paginator, CollectionNormalizer::FORMAT, ['uri' => 'http://localhost/foos?page=3']));
106+
$this->assertEquals($expected, $normalizer->normalize($paginator, CollectionNormalizer::FORMAT, ['request_uri' => '/foos?page=3']));
107107
}
108108

109109
public function testNormalizeArray()
@@ -119,7 +119,7 @@ public function testNormalizeArray()
119119
'foo',
120120
CollectionNormalizer::FORMAT,
121121
[
122-
'uri' => 'http://localhost/foos',
122+
'request_uri' => '/foos',
123123
'api_sub_level' => true,
124124
'resource_class' => 'Foo',
125125
]
@@ -139,7 +139,7 @@ public function testNormalizeArray()
139139
$normalizer->setNormalizer($itemNormalizer->reveal());
140140

141141
$expected = [
142-
'links' => ['self' => 'http://localhost/foos'],
142+
'links' => ['self' => '/foos'],
143143
'data' => [
144144
[
145145
'type' => 'Foo',
@@ -153,7 +153,7 @@ public function testNormalizeArray()
153153
'meta' => ['totalItems' => 1],
154154
];
155155

156-
$this->assertEquals($expected, $normalizer->normalize($data, CollectionNormalizer::FORMAT, ['uri' => 'http://localhost/foos']));
156+
$this->assertEquals($expected, $normalizer->normalize($data, CollectionNormalizer::FORMAT, ['request_uri' => '/foos']));
157157
}
158158

159159
/**
@@ -173,7 +173,7 @@ public function testNormalizeWithoutDataKey()
173173
'foo',
174174
CollectionNormalizer::FORMAT,
175175
[
176-
'uri' => 'http://localhost/foos',
176+
'request_uri' => '/foos',
177177
'api_sub_level' => true,
178178
'resource_class' => 'Foo',
179179
]
@@ -183,6 +183,6 @@ public function testNormalizeWithoutDataKey()
183183
$normalizer = new CollectionNormalizer($resourceClassResolverProphecy->reveal(), 'page');
184184
$normalizer->setNormalizer($itemNormalizer->reveal());
185185

186-
$normalizer->normalize($data, CollectionNormalizer::FORMAT, ['uri' => 'http://localhost/foos']);
186+
$normalizer->normalize($data, CollectionNormalizer::FORMAT, ['request_uri' => '/foos']);
187187
}
188188
}

0 commit comments

Comments
 (0)