/** * 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); } }