-
Notifications
You must be signed in to change notification settings - Fork 66
Description
About the extensive use of generators in BaseQueryParser
if ($queryParameters instanceof BaseQueryParserInterface) {
$encodingParameters = new EncodingParameters(
$queryParameters->getIncludes(),
$queryParameters->getFields()
);
}
Produces "TypeError: Argument 1 passed to Neomerx\JsonApi\Encoder\Parameters\EncodingParameters::__construct() must be of the type array or null, object given" because indeed they are \Generator instances and not an arrays
This can be solved by transforming \Generator to an array
if ($queryParameters instanceof BaseQueryParserInterface) {
$encodingParameters = new EncodingParameters(
\iterator_to_array($queryParameters->getIncludes()),
\iterator_to_array($queryParameters->getFields())
);
}
But this solution produces further problems because resulting array looses "resource key" and then when using fields in getFieldSet it always returns null
In the same fashion when traversing relationships to be included to response in getIncludeRelationships $includePaths are \Generator instances and thus getRelationshipNameForTopResource produces a Type error expecting an string
Generators are a great thing but they cannot be just dropped into a codebase, they need to be integrated with care at all levels (they are not really arrays and don't behave like them), in this scenario means taking care of EncodingParameters constructor and how getFieldSet method works at the very least, I haven't gone any further than this so I don't know if problems spread more
In the mean time I'm creating a custom implementation of BaseQueryParserInterface based on array usage