Skip to content

Commit efa3bb1

Browse files
committed
Pull request naneau#15 (Added Native PHP Copy Support)
1 parent b37d439 commit efa3bb1

File tree

1 file changed

+28
-50
lines changed

1 file changed

+28
-50
lines changed

src/Naneau/Obfuscator/Console/Command/ObfuscateCommand.php

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use Naneau\Obfuscator\Obfuscator;
1414
use Naneau\Obfuscator\Obfuscator\Event\File as FileEvent;
15-
use Naneau\Obfuscator\Obfuscator\Event\FileError as FileErrorEvent;
1615

1716
use Symfony\Component\Console\Command\Command;
1817
use Symfony\Component\Console\Input\InputArgument;
@@ -71,23 +70,11 @@ protected function configure()
7170
null,
7271
InputOption::VALUE_NONE,
7372
'Leave whitespace in output?'
74-
)->addOption(
75-
'ignore_error',
76-
null,
77-
InputOption::VALUE_NONE,
78-
'Continue processing the next file when error is encountered'
7973
)->addOption(
8074
'config',
8175
null,
8276
InputOption::VALUE_REQUIRED,
8377
'Configuration file to use'
84-
)->addOption(
85-
'memory_limit',
86-
null,
87-
InputOption::VALUE_REQUIRED,
88-
'Runtime memory when running the obsfucator. ' .
89-
'Example: 128M ' .
90-
'See http://php.net/manual/en/ini.core.php#ini.memory-limit'
9178
);
9279

9380
$this->setContainer(new Container);
@@ -105,10 +92,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
10592
// Finalize the container
10693
$this->finalizeContainer($input);
10794

108-
// Change runtime memory
109-
if($memory = $input->getOption('memory_limit')) {
110-
ini_set("memory_limit", $memory);
111-
}
11295
// Input/output dirs
11396
$inputDirectory = $input->getArgument('input_directory');
11497
$outputDirectory = $input->getArgument('output_directory');
@@ -130,7 +113,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
130113

131114
// Strip whitespace?
132115
$stripWhitespace = !$input->getOption('leave_whitespace');
133-
$ignoreError = !!$input->getOption('ignore_error');
134116

135117
// Show every file
136118
$this->getObfuscator()->getEventDispatcher()->addListener(
@@ -142,25 +124,9 @@ function(FileEvent $event) use ($output, $directory) {
142124
));
143125
}
144126
);
145-
// Show error processing file
146-
if($ignoreError) {
147-
$this->getObfuscator()->getEventDispatcher()->addListener(
148-
'obfuscator.file.error',
149-
function(FileErrorEvent $event) use ($output, $directory) {
150-
$output->writeln(sprintf(
151-
'Error obfuscating <error>%s</error>',
152-
substr($event->getFile(), strlen($directory))
153-
));
154-
$output->writeln(sprintf(
155-
'Parsing error: <error>%s</error>', $event->getErrorMessage()
156-
));
157-
}
158-
);
159-
}
160127

161128
// Actual obfuscation
162-
$this->getObfuscator()->obfuscate($directory, $stripWhitespace,
163-
$ignoreError);
129+
$this->getObfuscator()->obfuscate($directory, $stripWhitespace);
164130
}
165131

166132
/**
@@ -205,27 +171,39 @@ public function getObfuscator()
205171
**/
206172
private function copyDir($from, $to)
207173
{
208-
// FIXME implement native copy
209-
$output = array();
210-
$return = 0;
211-
212-
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
213-
// WINDOWS
214-
$command = sprintf('XCOPY "%s" "%s" /hievry', $from, $to);
215-
} else {
216-
// *NIX
217-
$command = sprintf('cp -rf %s %s', $from, $to);
218-
}
174+
$this->copyDirectory($from, $to);
219175

220-
exec($command, $output, $return);
221-
222-
if ($return !== 0) {
176+
if (!is_dir($to)) {
223177
throw new \Exception('Could not copy directory');
224178
}
225179

226180
return $this;
227181
}
228182

183+
/**
184+
* Recursively copy a directory
185+
*
186+
* @param string $src
187+
* @param string $dst
188+
* @return void
189+
**/
190+
private function copyDirectory($src,$dst)
191+
{
192+
$dir = opendir($src);
193+
@mkdir($dst);
194+
while(false !== ( $file = readdir($dir)) ) {
195+
if (( $file != '.' ) && ( $file != '..' )) {
196+
if ( is_dir($src . '/' . $file) ) {
197+
$this->copyDirectory($src . '/' . $file,$dst . '/' . $file);
198+
}
199+
else {
200+
copy($src . '/' . $file,$dst . '/' . $file);
201+
}
202+
}
203+
}
204+
closedir($dir);
205+
}
206+
229207
/**
230208
* Finalize the container
231209
*
@@ -251,4 +229,4 @@ private function finalizeContainer(InputInterface $input)
251229

252230
return $this;
253231
}
254-
}
232+
}

0 commit comments

Comments
 (0)