コード例 #1
0
ファイル: Validator.php プロジェクト: rfink/verdict
 /**
  * Validate given segment tree (or subtree, whatever it happens to be)
  * @param Tree $tree 
  * @return void
  * @throws RuntimeException
  */
 private function validateNode(Tree $tree)
 {
     $children = $tree->getChildren();
     for ($i = 0, $len = count($children); $i < $len; ++$i) {
         if ($i === $len - 1) {
             break;
         }
         $condition = $children[$i]->getCondition();
         $segmentName = $children[$i]->getSegmentName();
         if (!isset($condition)) {
             throw new RuntimeException('The segment ' . $segmentName . ' is not a default node, but has no valid condition');
         }
         $conditionType = $this->getConditionType($condition);
         if ($conditionType === 'composite') {
             $this->validateComposite($condition, $segmentName);
         } else {
             if ($conditionType === 'comparison') {
                 $this->validateComparison($condition, $segmentName);
             }
         }
         $this->validateNode($children[$i]);
     }
 }
コード例 #2
0
ファイル: Tree.php プロジェクト: rfink/verdict
 /**
  * Private method, does the brunt of getLeafNode, but is separate to allow recursion
  * @param Tree $segment
  * @param array $path
  * @return Tree 
  */
 private function walkTree(Tree $segment, &$path)
 {
     if (!$segment->evaluateCondition()) {
         return null;
     }
     if ($segment->isLeafNode()) {
         return $segment;
     }
     $path[] = $segment;
     /* @var $child Tree */
     foreach ($segment->getChildren() as $child) {
         $val = $this->walkTree($child, $path);
         if (isset($val)) {
             return $val;
         }
     }
     // Branch evaluated to false, pop the last path off
     array_pop($path);
 }