Exemple #1
0
 /**
  * Process dependencies hash. Makes topological sorting and gives operation order list
  *
  * @param array $depsHash
  * @param bool $sortReverse
  * @return array
  */
 protected function processDepsHash(&$depsHash, $sortReverse = true)
 {
     $nodes = array();
     $graph = new \Magento\Framework\Connect\Structures\Graph();
     foreach ($depsHash as $key => $data) {
         $node = new \Magento\Framework\Connect\Structures\Node();
         $nodes[$key] =& $node;
         unset($data['packages']);
         $node->setData($data);
         $graph->addNode($node);
         unset($node);
     }
     if (count($nodes) > 1) {
         foreach ($depsHash as $key => $data) {
             $packages = $data['packages'];
             foreach ($packages as $pdata) {
                 $pName = $pdata['name'];
                 if (isset($nodes[$key], $nodes[$pName])) {
                     $nodes[$key]->connectTo($nodes[$pName]);
                 }
             }
         }
     }
     if (!$graph->isAcyclic()) {
         throw new \Exception("Dependency references are cyclic");
     }
     $result = $graph->topologicalSort();
     $sortReverse ? krsort($result) : ksort($result);
     $out = array();
     foreach ($result as $nodes) {
         foreach ($nodes as $n) {
             /** @var $n \Magento\Framework\Connect\Structures\Node */
             $out[] = $n->getData();
         }
     }
     unset($graph, $nodes);
     return $out;
 }
Exemple #2
0
 /**
  * Process dependencies hash
  * Makes topological sorting and gives operation order list
  *
  * @param array &$depsHash
  * @param bool $sortReverse
  * @return array
  */
 protected function processDepsHash(&$depsHash, $sortReverse = true)
 {
     $nodes = array();
     $graph = new \Magento\Framework\Connect\Structures\Graph();
     foreach ($depsHash as $key => $data) {
         $packages = $data['packages'];
         $node = new \Magento\Framework\Connect\Structures\Node();
         $nodes[$key] =& $node;
         unset($data['packages']);
         $node->setData($data);
         $graph->addNode($node);
         unset($node);
     }
     if (count($nodes) > 1) {
         foreach ($depsHash as $key => $data) {
             $packages = $data['packages'];
             foreach ($packages as $pdata) {
                 $pName = $pdata['channel'] . "/" . $pdata['name'];
                 if (isset($nodes[$key], $nodes[$pName])) {
                     $nodes[$key]->connectTo($nodes[$pName]);
                 }
             }
         }
     }
     $result = $graph->topologicalSort();
     $sortReverse ? krsort($result) : ksort($result);
     $out = array();
     $total = 0;
     foreach ($result as $order => $nodes) {
         foreach ($nodes as $n) {
             $out[] = $n->getData();
         }
     }
     unset($graph, $nodes);
     return $out;
 }