/**
  * Dispatch a node.
  *
  * This method will look for a method of the form
  * "walk{NodeType}" in this class and then use that
  * to build the PHPCR QOM counterpart of the given node.
  *
  * @param AbstractNode $node
  *
  * @return object - PHPCR QOM object
  */
 public function dispatch(AbstractNode $node)
 {
     $methodName = sprintf('walk%s', $node->getName());
     if (!method_exists($this, $methodName)) {
         throw new InvalidArgumentException(sprintf('Do not know how to walk node of type "%s"', $node->getName()));
     }
     $res = $this->{$methodName}($node);
     return $res;
 }
Beispiel #2
0
 /**
  * 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();
 }