Skip to content

Instantly share code, notes, and snippets.

Last active December 28, 2015 04:09
What would you like to do?
use \Gliph\Graph\DirectedAdjacencyList;
use \Gliph\Traversal\DepthFirst;
$graph = new DirectedAdjacencyList();
foreach ($entity_list as $entity) {
if ($entity->has('embedded')) {
foreach ($entity->get('embedded') as $embedded) {
$graph->addDirectedEdge($entity, $embedded);
if ($cycles = $graph->getCycles()) {
throw new NaughtyCycleException(sprintf('BAAAAAD here are your cycles: %s', print_r($cycles, TRUE)));
$tsl = DepthFirst::toposort($graph);
foreach($tsl as $entity) {
// do your import thang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment