Skip to content

Instantly share code, notes, and snippets.

@sdboyer
Last active December 28, 2015 04:09
Show Gist options
  • Save sdboyer/7440131 to your computer and use it in GitHub Desktop.
Save sdboyer/7440131 to your computer and use it in GitHub Desktop.
<?php
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