/** * showParentsAndChildren * * @param \stdClass $output * @param ApiInterface $entity * @param Field $field * * @return void * @throws Exception */ private function showParentsAndChildren(\stdClass $output, ApiInterface $entity, Field $field) { if (in_array($field->getAlias(), $entity->getParentRelationships())) { /** @var ApiInterface $parentEntity */ $parentEntity = $entity->getRelated($field->getAlias()); if ($parentEntity === false) { //AKA, a nullable vendor $output->{$field->getAlias()} = null; } else { $output->{$field->getAlias()} = new \stdClass(); $this->showRecursive($output->{$field->getAlias()}, $field, $parentEntity); } } elseif (in_array($field->getAlias(), $entity->getChildrenRelationships())) { $output->{$field->getAlias()} = array(); $resultSet = $entity->getRelated($field->getAlias()); foreach ($resultSet as $key => $currentEntity) { $subOutput = new \stdClass(); $output->{$field->getAlias()}[] = $subOutput; $this->showRecursive($subOutput, $field, $currentEntity); } } else { throw new Exception('Invalid Field, not on the current object, no child or parent found: ' . $entity->getEntityName() . ' with ' . $field->getAlias(), 400); } }