From 0f3e5908b580a37e69b99d97215dcf51c49599f5 Mon Sep 17 00:00:00 2001 From: SikiFn Date: Thu, 9 Apr 2015 13:47:42 +0300 Subject: [PATCH] Added Native PHP Copy Support 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. --- .../Console/Command/ObfuscateCommand.php | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Naneau/Obfuscator/Console/Command/ObfuscateCommand.php b/src/Naneau/Obfuscator/Console/Command/ObfuscateCommand.php index 3d3f1dd..139eb24 100644 --- a/src/Naneau/Obfuscator/Console/Command/ObfuscateCommand.php +++ b/src/Naneau/Obfuscator/Console/Command/ObfuscateCommand.php @@ -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