Skip to content

Commit 21712f5

Browse files
committed
JsonApiResponseFactory::createResponse() meta and links arguments
1 parent 07f70b8 commit 21712f5

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
- Data Transfer Object classes generation from swagger spec
11+
- JsonApiResponseFactory::createResponse() `meta` and `links` arguments
1112

1213
## [0.0.14] - 2021-02-02
1314
### Added

src/FreeElephants/JsonApiToolkit/Psr/JsonApiResponseFactory.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,31 @@ public function __construct(EncoderInterface $encoder, ResponseFactoryInterface
2222
$this->errorFactory = $errorFactory;
2323
}
2424

25-
public function createResponse($data, ServerRequestInterface $request = null): ResponseInterface
25+
public function createResponse($data, ServerRequestInterface $request = null, $meta = null, array $links = []): ResponseInterface
2626
{
2727
$includedPath = [];
28+
$fieldSets = [];
2829
if ($request) {
2930
$queryParams = $request->getQueryParams();
31+
3032
if (array_key_exists('include', $queryParams)) {
3133
$includedPath = explode(',', $queryParams['include']);
3234
}
33-
}
3435

35-
$fieldSets = [];
36-
if ($request) {
37-
$queryParams = $request->getQueryParams();
3836
if (array_key_exists('fields', $queryParams)) {
3937
foreach ($queryParams['fields'] as $type => $typeFieldsString) {
4038
$fieldSets[$type] = explode(',', $typeFieldsString);
4139
}
4240
}
4341
}
44-
$content = $this->encoder->withIncludedPaths($includedPath)->withFieldSets($fieldSets)->encodeData($data);
42+
43+
$encoder = $this->encoder
44+
->withIncludedPaths($includedPath)
45+
->withFieldSets($fieldSets)
46+
->withMeta($meta)
47+
->withLinks($links);
48+
49+
$content = $encoder->encodeData($data);
4550

4651
$response = $this->createPsrResponse();
4752
$response->getBody()->write($content);

0 commit comments

Comments
 (0)