Example #1
0
 /**
  * @param $nodes
  *
  * @return Node
  */
 public static function buildTreeFromAwl($nodes)
 {
     $prevStep = false;
     $conj = false;
     $builder = new self();
     foreach ($nodes as $node) {
         $key = key($node);
         $contents = current($node);
         if (is_array($contents)) {
             $contents = self::buildTreeFromAwl($contents);
         }
         $contents = [$contents];
         if ($key === 'workflow') {
             $builder->add('workflow', $contents)->start();
             continue;
         }
         if ($key === 'step') {
             if ($prevStep) {
                 $builder->end();
             }
             $prevStep = true;
             $builder->add('step', $contents)->start();
             continue;
         }
         if ($key === 'conj') {
             $conj = true;
             $builder->start();
             continue;
         }
         $builder->add($key, $contents);
         if ($conj) {
             $conj = false;
             $builder->end();
         }
     }
     return $builder->retrieve(0);
 }