Ejemplo n.º 1
0
 /**
  * @param INode $node
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function append(INode $node)
 {
     if (in_array($node->nodeName(), $this->allowableChildren)) {
         $max = $this->maximumChildren();
         if ($max > 0 && count($this->children) >= $max) {
             throw new \LogicException('Node of type "' . $this->nodeName() . '" already has it\'s ' . 'maximum of "' . $max . '" children.  Cannot append child with definition "' . (string) $node . '"');
         }
         $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())));
 }
Ejemplo n.º 2
0
 /**
  * Adds a new childnode to this collection
  *
  * @param INode $child
  * @return void
  */
 public function addChild(INode $child)
 {
     $this->children[$child->getName()] = $child;
 }
Ejemplo n.º 3
0
 /**
  * copyNode
  *
  * @param INode $source
  * @param ICollection $destinationParent
  * @param string $destinationName
  * @return void
  */
 protected function copyNode(INode $source, ICollection $destinationParent, $destinationName = null)
 {
     if (!$destinationName) {
         $destinationName = $source->getName();
     }
     if ($source instanceof IFile) {
         $data = $source->get();
         // If the body was a string, we need to convert it to a stream
         if (is_string($data)) {
             $stream = fopen('php://temp', 'r+');
             fwrite($stream, $data);
             rewind($stream);
             $data = $stream;
         }
         $destinationParent->createFile($destinationName, $data);
         $destination = $destinationParent->getChild($destinationName);
     } elseif ($source instanceof ICollection) {
         $destinationParent->createDirectory($destinationName);
         $destination = $destinationParent->getChild($destinationName);
         foreach ($source->getChildren() as $child) {
             $this->copyNode($child, $destination);
         }
     }
     if ($source instanceof IProperties && $destination instanceof IProperties) {
         $props = $source->getProperties(array());
         $destination->updateProperties($props);
     }
 }
Ejemplo n.º 4
0
 public function match(INode $token)
 {
     return strcmp($this->compare->getName(), $token->getName()) === 0;
 }
 /**
  * @return int 
  */
 public function addNode(INode $node)
 {
     $this->childrens[] = $node;
     $node->setParent($this);
     return sizeof($this->childrens) - 1;
 }
Ejemplo n.º 6
0
 public function visit(INode $node, stdClass $obj)
 {
     $node->acceptChildren($this, $obj);
 }