Skip to content

Commit

Permalink
Added Native PHP Copy Support
Browse files Browse the repository at this point in the history
The script no more relies on *nix "cp" command.
Native PHP copy support has been added.
Therefore, the script can be used on windows now also.
  • Loading branch information
SikiFn committed Apr 9, 2015
1 parent 27af06d commit 0f3e590
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/Naneau/Obfuscator/Console/Command/ObfuscateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,38 @@ public function getObfuscator()
**/
private function copyDir($from, $to)
{
// FIXME implement native copy
$output = array();
$return = 0;
$command = sprintf('cp -rf %s %s', $from, $to);

exec($command, $output, $return);

if ($return !== 0) {
$this->copyDirectory($from, $to);

if (!is_dir($to)) {
throw new \Exception('Could not copy directory');
}

return $this;
}

/**
* Recursively copy a directory
*
* @param string $src
* @param string $dst
* @return void
**/
private function copyDirectory($src,$dst)
{
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
$this->copyDirectory($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}

/**
* Finalize the container
Expand Down

0 comments on commit 0f3e590

Please sign in to comment.