function transformToIterable($finder) { if (is_string($finder)) { if (file_exists($finder)) { return new FinderResult(array($finder), '.'); } return Finder::type(Finder::TYPE_ANY)->name($finder)->in('.'); } else { if ($finder instanceof Finder) { return $finder->in('.'); } else { if (is_array($finder)) { return $finder; } else { if ($finder instanceof \IteratorAggregate) { return $finder; } } } } throw new \InvalidArgumentException('Argument must be one of string, array or finder'); }
/** * Mirrors a directory to another. * * @param string $originDir The origin directory * @param string $targetDir The target directory * @param Finder $finder An Finder instance * @param array $options An array of options (see copy()) */ public function mirror($originDir, $targetDir, $finder = null, $options = array()) { if (null === $finder) { $finder = Finder::type('any'); } foreach ($finder->relative()->in($originDir) as $file) { if (is_dir($originDir . DIRECTORY_SEPARATOR . $file)) { $this->mkdirs($targetDir . DIRECTORY_SEPARATOR . $file); } else { if (is_file($originDir . DIRECTORY_SEPARATOR . $file)) { $this->copy($originDir . DIRECTORY_SEPARATOR . $file, $targetDir . DIRECTORY_SEPARATOR . $file, $options); } else { if (is_link($originDir . DIRECTORY_SEPARATOR . $file)) { $this->symlink($originDir . DIRECTORY_SEPARATOR . $file, $targetDir . DIRECTORY_SEPARATOR . $file); } else { throw new \RuntimeException(sprintf('Unable to guess "%s" file type.', $file)); } } } } }