protected function doWalkConstraintComposite(AbstractNode $node, $method) { $children = $node->getChildren(); if (0 === count($children)) { throw new \InvalidArgumentException('Composite must have at least one constraint'); } if (1 === count($children)) { return $this->dispatch(current($children)); } $lConstraint = array_shift($children); $lPhpcrConstraint = $this->dispatch($lConstraint); $phpcrComposite = false; foreach ($children as $rConstraint) { $rPhpcrConstraint = $this->dispatch($rConstraint); $phpcrComposite = $this->qomf()->{$method}($lPhpcrConstraint, $rPhpcrConstraint); $lPhpcrConstraint = $phpcrComposite; } return $phpcrComposite; }
/** * Add a child to this node. * * Exception will be thrown if child node type is not * described in the cardinality map, or if the maxiumum * permitted number of nodes would be exceeded by adding * the given child node. * * The given node will be returned EXCEPT when the current * node is a leaf node, in which case we return the parent. * * @throws OutOfBoundsException * * @return AbstractNode */ public function addChild(AbstractNode $node) { $cardinalityMap = $this->getCardinalityMap(); $nodeType = $node->getNodeType(); $validChild = true; $end = false; // if proposed child node is of an invalid type if (!isset($cardinalityMap[$nodeType])) { throw new OutOfBoundsException(sprintf('QueryBuilder node "%s" of type "%s" cannot be appended to "%s". ' . 'Must be one type of "%s"', $node->getName(), $nodeType, $this->getName(), implode(', ', array_keys($cardinalityMap)))); } $currentCardinality = isset($this->children[$node->getName()]) ? count($this->children[$node->getName()]) : 0; list($min, $max) = $cardinalityMap[$nodeType]; // if bounded and cardinality will exceed max if (null !== $max && $currentCardinality + 1 > $max) { throw new OutOfBoundsException(sprintf('QueryBuilder node "%s" cannot be appended to "%s". ' . 'Number of "%s" nodes cannot exceed "%s"', $node->getName(), $this->getName(), $nodeType, $max)); } $this->children[$nodeType][] = $node; return $node->getNext(); }
/** * @param AbstractNode $parentNode * @param string $field * @param array $values */ private function getInConstraint(AbstractNode $parentNode, $field, array $values) { $orNode = $parentNode->orx(); foreach ($values as $value) { $orNode->eq()->field($this->getField($field))->literal($value); } $orNode->end(); }
protected function doWalkConstraintComposite(AbstractNode $node, $method) { $children = $node->getChildren(); if (count($children) == 1) { $op = $this->dispatch(current($children)); return $op; } $lConstraint = array_shift($children); $lPhpcrConstraint = $this->dispatch($lConstraint); foreach ($children as $rConstraint) { $rPhpcrConstraint = $this->dispatch($rConstraint); $phpcrComposite = $this->qomf->{$method}($lPhpcrConstraint, $rPhpcrConstraint); $lPhpcrConstraint = $phpcrComposite; } return $phpcrComposite; }