Last active
December 28, 2015 04:09
-
-
Save sdboyer/7440131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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