Exemplo n.º 1
0
 /**
  * @param INode $node
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function append(INode $node)
 {
     if (in_array($node->nodeName(), $this->allowableChildren)) {
         $node->setParent($this);
         $this->children[] = $node;
         return $this;
     }
     throw new \InvalidArgumentException(sprintf('Node "%s" cannot be added to "%s".  Allowable child nodes: ["%s"].', $node->nodeName(), $this->nodeName(), implode('", "', $this->getAllowableChildren())));
 }
Exemplo n.º 2
0
 /**
  * @param INode|AbstractHump $parent
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function setParent($parent)
 {
     if (!$parent instanceof AbstractHump && !$parent instanceof INode) {
         throw new \InvalidArgumentException('Argument 1 expected to be instance of AbstractHump or INode.');
     }
     if (in_array($parent->nodeName(), $this->getAllowableParents(), true)) {
         $this->parent = $parent;
         return $this;
     }
     throw new \InvalidArgumentException(sprintf('Node "%s" cannot be added to passed parent "%s".  Allowable Parent Nodes: ["%s"].', $this->nodeName(), $parent->nodeName(), implode('", "', $this->getAllowableParents())));
 }
Exemplo n.º 3
0
 /**
  * @param string $nodeName
  * @return INode
  * @throws \LogicException
  * @throws \InvalidArgumentException
  */
 public function root($nodeName)
 {
     if (!is_string($nodeName)) {
         throw new \InvalidArgumentException('Argument 1 expected to be string, ' . gettype($nodeName) . ' seen.');
     }
     if (isset($this->rootNode)) {
         throw new \LogicException('"Where" nodes can only have a single immediate child element.  Current child name: ' . $this->rootNode->nodeName() . '".  Cannot add "' . $nodeName . '" as a 2nd immediate child.');
     }
     $nodeName = strtolower(trim($nodeName));
     if (isset($this->allowableChildren[$nodeName])) {
         $class = $this->nodeClassMap[$this->allowableChildren[$nodeName]];
         $this->rootNode = new $class();
         $this->rootNode->setParent($this);
         return $this->rootNode;
     }
     throw new \InvalidArgumentException('The node "' . $nodeName . '" does not map to a known node type.');
 }