/** * Recursive function to generate default expose columns * * @param array $fields - array to be populated recursively (referenced) * @param string $class - name of the class to process * @param EntityManagerRegistry $emr - entity manager registry used to fetch class information * @param integer $depth - maximum depth you want to travel through the relations * @param integer $fetchType - The fetch type to be used * @param integer|null $fetchType - The required fetch type of the relation */ protected function processExposeDepth(&$fields, $class, EntityManagerRegistry $emr, $depth = 0, $fetchType = null) { $this->registered_expose_classes[] = $class; if ($depth > 0) { /** @var \Doctrine\ORM\Mapping\ClassMetaData $metaData */ $metaData = $emr->getManagerForClass($class)->getClassMetadata($class); $fields = $metaData->getColumnNames(); if ($depth - 1 > 0) { --$depth; foreach ($metaData->getAssociationMappings() as $key => $assocMapping) { if (!in_array($assocMapping['targetEntity'], $this->registered_expose_classes) && (is_null($fetchType) || $assocMapping['fetch'] == $fetchType)) { $this->processExposeDepth($fields[$key], $assocMapping['targetEntity'], $emr, $depth, $fetchType); } } } } }