eosnewmedia / JSON-API-Common

Basic php implementation (shared structures for client and server) of the json api specification (jsonapi.org)
https://eosnewmedia.github.io/JSON-API-Common/
MIT License
14 stars 13 forks source link

Array properties should be defined as array #14

Closed legendik closed 6 years ago

legendik commented 6 years ago

Without this fix it triggers errors like. in_array() expects parameter 2 to be array, null given

pmarien commented 6 years ago

@legendik how can the error be reproduced? In fact, the constructor calls the methods "parseUriPath" and "parseUriQuery", which set all the required values.

legendik commented 6 years ago

@pmarien

$relationship = new \Enm\JsonApi\Model\Resource\Relationship\Relationship('signatures');
$jsonResource = new \Enm\JsonApi\Model\Resource\JsonResource('configs', '7', ['some' => 'data']);
$jsonResource->relationships()->set($relationship);
$document = new \Enm\JsonApi\Model\Document\Document($jsonResource);
$request = new \Enm\JsonApi\Model\Request\Request(
    'GET',
    new \GuzzleHttp\Psr7\Uri('http://server/v1/configs/7'),
    $document,
    'v1'
);

var_dump($request->createSubRequest('signatures'));

If url contains ?include=foo, the problem is gone, because of these lines: https://github.com/eosnewmedia/JSON-API-Common/blob/master/src/Model/Request/Request.php#L202-L205

Otherwise Request::currentLevelIncludes stays null, because $includes is empty and the error is thrown.

pmarien commented 6 years ago

ok, thanks! i have merged the pull request and tagged it as 3.1.3

legendik commented 6 years ago

Thanks! 🎉