12
12
13
13
use Naneau \Obfuscator \Obfuscator ;
14
14
use Naneau \Obfuscator \Obfuscator \Event \File as FileEvent ;
15
- use Naneau \Obfuscator \Obfuscator \Event \FileError as FileErrorEvent ;
16
15
17
16
use Symfony \Component \Console \Command \Command ;
18
17
use Symfony \Component \Console \Input \InputArgument ;
@@ -71,23 +70,11 @@ protected function configure()
71
70
null ,
72
71
InputOption::VALUE_NONE ,
73
72
'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 '
79
73
)->addOption (
80
74
'config ' ,
81
75
null ,
82
76
InputOption::VALUE_REQUIRED ,
83
77
'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 '
91
78
);
92
79
93
80
$ this ->setContainer (new Container );
@@ -105,10 +92,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
105
92
// Finalize the container
106
93
$ this ->finalizeContainer ($ input );
107
94
108
- // Change runtime memory
109
- if ($ memory = $ input ->getOption ('memory_limit ' )) {
110
- ini_set ("memory_limit " , $ memory );
111
- }
112
95
// Input/output dirs
113
96
$ inputDirectory = $ input ->getArgument ('input_directory ' );
114
97
$ outputDirectory = $ input ->getArgument ('output_directory ' );
@@ -130,7 +113,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
130
113
131
114
// Strip whitespace?
132
115
$ stripWhitespace = !$ input ->getOption ('leave_whitespace ' );
133
- $ ignoreError = !!$ input ->getOption ('ignore_error ' );
134
116
135
117
// Show every file
136
118
$ this ->getObfuscator ()->getEventDispatcher ()->addListener (
@@ -142,25 +124,9 @@ function(FileEvent $event) use ($output, $directory) {
142
124
));
143
125
}
144
126
);
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
- }
160
127
161
128
// Actual obfuscation
162
- $ this ->getObfuscator ()->obfuscate ($ directory , $ stripWhitespace ,
163
- $ ignoreError );
129
+ $ this ->getObfuscator ()->obfuscate ($ directory , $ stripWhitespace );
164
130
}
165
131
166
132
/**
@@ -205,27 +171,39 @@ public function getObfuscator()
205
171
**/
206
172
private function copyDir ($ from , $ to )
207
173
{
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 );
219
175
220
- exec ($ command , $ output , $ return );
221
-
222
- if ($ return !== 0 ) {
176
+ if (!is_dir ($ to )) {
223
177
throw new \Exception ('Could not copy directory ' );
224
178
}
225
179
226
180
return $ this ;
227
181
}
228
182
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
+
229
207
/**
230
208
* Finalize the container
231
209
*
@@ -251,4 +229,4 @@ private function finalizeContainer(InputInterface $input)
251
229
252
230
return $ this ;
253
231
}
254
- }
232
+ }
0 commit comments