Example #1
0
 /**
  * Execute the chain
  */
 public function execute()
 {
     for ($i = 0; $i < count($this->rules); $i++) {
         $this->rules[$i]->execute();
         echo "LinkType: " . $this->rules[$i]->linkType . "\n";
         switch ($this->rules[$i]->linkType) {
             case "NONE":
                 break;
             case "LOOP":
                 // Find the matching endloop, extract the subarray as a new chain and loop
                 // execution for each row
                 echo "DETECTED LOOP\n";
                 if (count($this->rules) - ($i + 1) > 0) {
                     //                    if(((count($this->rules)-1)-$i) > 0) {
                     $endindex = $this->getEndLoopIndex($i + 1);
                     echo "LOOP START\n";
                     echo $i . ": LOOP RULE Index\n";
                     $loopcount = 0;
                     $loopchain = NULL;
                     while ($row = $this->rules[$i]->getNextResultRow()) {
                         echo $i + 1 . ": INNER RULE Index\n";
                         echo $endindex . ": Endindex\n";
                         $loopcount++;
                         echo "INNER RULE ITERATION COUNTER: " . $loopcount . "\n";
                         echo "Offset: " . ($i + 1) . "\n";
                         echo "Length: " . ($endindex - $i) . "\n";
                         $loopchain = new self(null, \array_slice($this->rules, $i + 1, $endindex - $i), $row, FALSE);
                         $loopchain->execute();
                         echo "CURRENT LOOP RULE\n";
                         if (in_array($this->rules[$endindex]->resultType, ['ROW', 'RECORDSET'])) {
                             $this->rules[$endindex]->setOutput($loopchain->getChainResult());
                         }
                     }
                     echo "LOOP END\n";
                     $i = $endindex + 1;
                     echo $i . ": Current Index\n";
                 }
                 break;
             case "ENDLOOP":
                 break;
             case "NEXT":
                 if (count($this->rules) - $i > 1) {
                     $this->rules[$i + 1]->input = clone $this->rules[$i]->input;
                 }
                 break;
             default:
                 // do nothing
                 break;
         }
     }
 }