/**
* import
*
* @param string $sourceDir
* @param DocumentNodeInterface $targetNode
* @param array $excludes
*/
public function import($sourceDir, DocumentNodeInterface $targetNode, array $excludes = array())
{
if (!is_dir($sourceDir)) {
throw new \InvalidArgumentException(sprintf('The directory %s does not exist', $sourceDir));
}
$this->emn->persist($targetNode);
$currentNode = array(0 => $targetNode);
$finder = new Finder();
$finder->in($sourceDir);
$files = $finder->getIterator();
foreach ($files as $file) {
foreach ($excludes as $exclude) {
if (strpos($file->getRelativePathname(), $exclude) !== false) {
continue 2;
}
}
$depth = $files->getDepth();
if ($file->isDir()) {
$currentNode[$depth + 1] = $this->importDir($currentNode, $depth, $file, $targetNode);
} elseif ($file->isFile()) {
$this->importFile($currentNode, $depth, $file);
}
}
$this->emn->flush();
}