@@ -659,7 +659,7 @@ protected function object2Array(object $object, array $expands = []): array
659659 /**
660660 * Uniform conversion of php array to JSON output
661661 */
662- protected function ret2json (array $ result ): string
662+ protected static function ret2json (array $ result ): string
663663 {
664664 return json_encode ($ result , JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR ) . PHP_EOL ;
665665 }
@@ -1159,7 +1159,7 @@ protected function getQueryParameterFamily(Request $request, string $family): ar
11591159 return $ retval ;
11601160 }
11611161
1162- static function createJsonResponse (array $ data = [], array $ links = [], array $ included = []) {
1162+ static function createJsonResponse (array $ data = [], array $ links = [], array $ included = [], array $ meta = [] ) {
11631163 $ response = [
11641164 "jsonapi " => [
11651165 "version " => "1.1 " ,
@@ -1173,6 +1173,10 @@ static function createJsonResponse(array $data = [], array $links = [], array $i
11731173 $ response ["links " ] = $ links ;
11741174 }
11751175
1176+ if (!empty ($ meta )) {
1177+ $ response ["meta " ] = $ meta ;
1178+ }
1179+
11761180 $ response ["data " ] = $ data ;
11771181
11781182 if (!empty ($ included )) {
@@ -1251,6 +1255,15 @@ protected static function getOneResource(object $apiClass, object $object, Reque
12511255 //case of a POST request
12521256 }
12531257
1258+ //Meta response for helper functions that do not respond with resource records
1259+ protected static function getMetaResponse (array $ meta , Request $ request , Response $ response , int $ statusCode =200 ) {
1260+ $ ret = self ::createJsonResponse ($ meta =$ meta );
1261+ $ body = $ response ->getBody ();
1262+ $ body ->write (self ::ret2json ($ ret ));
1263+
1264+ return $ response ->withStatus ($ statusCode )->withHeader ("Content-Type " , "application/vnd.api+json " );
1265+ }
1266+
12541267 /**
12551268 * Override-able activated methods
12561269 */
0 commit comments