private function parseData()
{
list($isEmpty, $isOriginallyArrayed, $traversableData) = $this->analyzeCurrentData();
/** @var bool $isEmpty */
/** @var bool $isOriginallyArrayed */
if ($isEmpty === true) {
(yield $this->createReplyForEmptyData($traversableData));
} else {
$curFrame = $this->stack->end();
// if resource(s) is in primary data section (not in included)
$isPrimary = $curFrame->getLevel() < 2;
foreach ($traversableData as $resource) {
$schema = $this->getSchema($resource, $curFrame);
$fieldSet = $this->getFieldSet($schema->getResourceType());
$resourceObject = $schema->createResourceObject($resource, $isOriginallyArrayed, $fieldSet);
$isCircular = $this->checkCircular($resourceObject);
$this->stack->setCurrentResource($resourceObject);
(yield $this->createReplyResourceStarted());
// duplicated are allowed in data however they shouldn't be in includes
if ($isCircular === true && $isPrimary === false) {
continue;
}
if ($this->shouldParseRelationships() === true) {
$relationships = $this->getIncludeRelationships();
$relObjectIterator = $schema->getRelationshipObjectIterator($resource, $isPrimary, $relationships);
foreach ($relObjectIterator as $relationship) {
/** @var RelationshipObjectInterface $relationship */
$nextFrame = $this->stack->push();
$nextFrame->setRelationship($relationship);
try {
if ($this->isRelationshipIncludedOrInFieldSet() === true) {
foreach ($this->parseData() as $parseResult) {
(yield $parseResult);
}
}
} finally {
$this->stack->pop();
}
}
}
(yield $this->createReplyResourceCompleted());
}
}
}