Esempio n. 1
0
 /**
  * @param GroupNode $rootNode
  *
  * @return boolean
  */
 protected function isValid(GroupNode $rootNode)
 {
     if ($rootNode->getType() !== GroupNode::TYPE_MIXED) {
         return true;
     }
     $types = array_map(function ($node) {
         if ($node instanceof GroupNode) {
             return $node->getType();
         }
         return $node->isComputed() ? GroupNode::TYPE_COMPUTED : GroupNode::TYPE_UNCOMPUTED;
     }, $rootNode->getChildren());
     if (in_array(GroupNode::TYPE_MIXED, $types)) {
         return false;
     }
     $computedTypes = ArrayUtil::dropWhile(function ($type) {
         return $type === GroupNode::TYPE_UNCOMPUTED;
     }, $types);
     return !in_array(GroupNode::TYPE_UNCOMPUTED, $computedTypes);
 }
Esempio n. 2
0
 /**
  * @param GroupNode $gNode
  *
  * @return mixed Expr[] Where first item is uncomputed expr and 2nd one is computed
  */
 protected function resolveGroupNode(GroupNode $gNode)
 {
     $uncomputedRestrictions = [];
     $computedRestrictions = [];
     foreach ($gNode->getChildren() as $node) {
         if ($node instanceof Restriction) {
             if ($node->isComputed()) {
                 $computedRestrictions[] = $node;
             } else {
                 $uncomputedRestrictions[] = $node;
             }
         } else {
             list($uncomputedExpr, $computedExpr) = $this->resolveGroupNode($node);
             if ($uncomputedExpr) {
                 $uncomputedRestrictions[] = new Restriction($uncomputedExpr, $node->getCondition(), false);
             }
             if ($computedExpr) {
                 $computedRestrictions[] = new Restriction($computedExpr, $node->getCondition(), true);
             }
         }
     }
     return [$this->createExprFromRestrictions($uncomputedRestrictions), $this->createExprFromRestrictions($computedRestrictions)];
 }