BackUpWordPress - Version 3.5-beta

Version Description

= 3.4 =

  • This version introduces a major refactoring of the code responsible for the core backup engine. We made sure to write unit tests for the new code, and we have tested it on several user's sites. It fixes a lot of old bugs, and Windows users should see major improvements to reliability.

= 3.3.4 =

  • WordPress 4.4 compatibility.

= 3.3.1 =

  • Fixes a bug that would prevent downloading backups since 3.3.0 - please update.

= 3.2.5 =

  • Security fixes related to add_query_arg

= 3.2.1 =

  • Important bug fixes. Please upgrade to this version to avoid incomplete or broken backups.

= 3.1.3 =

  • Fixes backwards compatibility for add-ons and avoids a Fatal Error. Please upgrade straight to this version before upgrading your add-ons.

= 3.0.4 =

  • Fixes a few minor bugs. Immediate update is recommended.

= 3.0.2 =

  • Important: we have dropped support for PHP 5.2, you will not be able to activate BackUpWordPress on a server running PHP versions older than PHP 5.3.29

= 3.0.1 =

  • This is a critical update. Fixes a bug in the core backup library. Please update immediately.
Download this release

Release Info

Developer pauldewouters
Plugin Icon 128x128 BackUpWordPress
Version 3.5-beta
Comparing to
See all releases

Code changes from version 3.4.5 to 3.5-beta

Files changed (58) hide show
  1. admin/actions.php +4 -4
  2. admin/schedule-form-excludes.php +67 -84
  3. admin/schedule-form.php +1 -1
  4. backupwordpress.php +1 -1
  5. classes/backup/class-backup-engine-database-mysqldump.php +23 -48
  6. classes/backup/class-backup-engine-database.php +1 -5
  7. classes/backup/class-backup-engine-file-zip.php +25 -21
  8. classes/backup/class-backup-engine-file.php +1 -2
  9. classes/backup/class-backup-utilities.php +11 -70
  10. classes/backup/class-backup.php +11 -1
  11. classes/class-path.php +7 -2
  12. classes/class-plugin.php +1 -1
  13. classes/class-requirement.php +27 -139
  14. classes/class-site-size.php +21 -7
  15. composer.json +3 -2
  16. composer.lock +56 -7
  17. functions/core.php +7 -2
  18. languages/backupwordpress.pot +28 -28
  19. uninstall.php +7 -0
  20. vendor/composer/ClassLoader.php +4 -4
  21. vendor/composer/autoload_psr4.php +1 -0
  22. vendor/composer/autoload_real.php +0 -5
  23. vendor/composer/installed.json +87 -36
  24. vendor/symfony/finder/Adapter/AbstractFindAdapter.php +1 -1
  25. vendor/symfony/finder/Glob.php +1 -1
  26. vendor/symfony/finder/Iterator/FilterIterator.php +12 -10
  27. vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php +4 -2
  28. vendor/symfony/finder/SplFileInfo.php +4 -0
  29. vendor/symfony/process/CHANGELOG.md +40 -0
  30. vendor/symfony/process/Exception/ExceptionInterface.php +21 -0
  31. vendor/symfony/process/Exception/InvalidArgumentException.php +21 -0
  32. vendor/symfony/process/Exception/LogicException.php +21 -0
  33. vendor/symfony/process/Exception/ProcessFailedException.php +54 -0
  34. vendor/symfony/process/Exception/ProcessTimedOutException.php +69 -0
  35. vendor/symfony/process/Exception/RuntimeException.php +21 -0
  36. vendor/symfony/process/ExecutableFinder.php +90 -0
  37. vendor/symfony/process/LICENSE +19 -0
  38. vendor/symfony/process/PhpExecutableFinder.php +90 -0
  39. vendor/symfony/process/PhpProcess.php +78 -0
  40. vendor/symfony/process/Pipes/AbstractPipes.php +74 -0
  41. vendor/symfony/process/Pipes/PipesInterface.php +60 -0
  42. vendor/symfony/process/Pipes/UnixPipes.php +214 -0
  43. vendor/symfony/process/Pipes/WindowsPipes.php +253 -0
  44. vendor/symfony/process/Process.php +1507 -0
  45. vendor/symfony/process/ProcessBuilder.php +287 -0
  46. vendor/symfony/process/ProcessUtils.php +115 -0
  47. vendor/symfony/process/Tests/ExecutableFinderTest.php +144 -0
  48. vendor/symfony/process/Tests/NonStopableProcess.php +47 -0
  49. vendor/symfony/process/Tests/PhpExecutableFinderTest.php +119 -0
  50. vendor/symfony/process/Tests/PhpProcessTest.php +49 -0
  51. vendor/symfony/process/Tests/PipeStdinInStdoutStdErrStreamSelect.php +72 -0
  52. vendor/symfony/process/Tests/ProcessBuilderTest.php +225 -0
  53. vendor/symfony/process/Tests/ProcessFailedExceptionTest.php +146 -0
  54. vendor/symfony/process/Tests/ProcessTest.php +1244 -0
  55. vendor/symfony/process/Tests/ProcessUtilsTest.php +48 -0
  56. vendor/symfony/process/Tests/SignalListener.php +21 -0
  57. vendor/symfony/process/composer.json +33 -0
  58. vendor/symfony/process/phpunit.xml.dist +28 -0
admin/actions.php CHANGED
@@ -499,7 +499,7 @@ function calculate_site_size() {
499
 
500
  $site_size = new Site_Size;
501
 
502
- if ( ! $site_size::is_site_size_cached() ) {
503
  $root = new \SplFileInfo( Path::get_root() );
504
  $site_size->filesize( $root );
505
  }
@@ -535,10 +535,10 @@ function heartbeat_received( $response, $data ) {
535
 
536
  if ( ! empty( $data['hmbkp_client_request'] ) ) {
537
 
538
- // Pass the site size to be displayed when it's ready.
539
- if ( Site_Size::is_site_size_cached() ) {
540
 
541
- $site_size = new Site_Size( $schedule->get_type(), $schedule->get_excludes() );
 
542
 
543
  $response['hmbkp_site_size'] = $site_size->get_formatted_site_size();
544
 
499
 
500
  $site_size = new Site_Size;
501
 
502
+ if ( ! $site_size->is_site_size_cached() ) {
503
  $root = new \SplFileInfo( Path::get_root() );
504
  $site_size->filesize( $root );
505
  }
535
 
536
  if ( ! empty( $data['hmbkp_client_request'] ) ) {
537
 
538
+ $site_size = new Site_Size( $schedule->get_type(), $schedule->get_excludes() );
 
539
 
540
+ // Pass the site size to be displayed when it's ready.
541
+ if ( $site_size->is_site_size_cached() ) {
542
 
543
  $response['hmbkp_site_size'] = $site_size->get_formatted_site_size();
544
 
admin/schedule-form-excludes.php CHANGED
@@ -57,7 +57,7 @@ $user_excludes = $excludes->get_user_excludes(); ?>
57
 
58
  <a href="<?php echo admin_action_url( 'remove_exclude_rule', array(
59
  'hmbkp_remove_exclude' => $exclude,
60
- 'hmbkp_schedule_id' => $schedule->get_id()
61
  ) ); ?>" class="delete-action"><?php _e( 'Stop excluding', 'backupwordpress' ); ?></a>
62
 
63
  <?php endif; ?>
@@ -89,7 +89,6 @@ $user_excludes = $excludes->get_user_excludes(); ?>
89
  if ( false !== strpos( $untrusted_directory, Path::get_root() ) && is_dir( $untrusted_directory ) ) {
90
  $directory = $untrusted_directory;
91
  }
92
-
93
  }
94
 
95
  $exclude_string = implode( '|', $excludes->get_excludes_for_regex() );
@@ -103,102 +102,98 @@ $user_excludes = $excludes->get_user_excludes(); ?>
103
 
104
  <thead>
105
 
106
- <tr>
107
- <th></th>
108
- <th scope="col"><?php _e( 'Name', 'backupwordpress' ); ?></th>
109
- <th scope="col" class="column-format"><?php _e( 'Size', 'backupwordpress' ); ?></th>
110
- <th scope="col" class="column-format"><?php _e( 'Permissions', 'backupwordpress' ); ?></th>
111
- <th scope="col" class="column-format"><?php _e( 'Type', 'backupwordpress' ); ?></th>
112
- <th scope="col" class="column-format"><?php _e( 'Status', 'backupwordpress' ); ?></th>
113
- </tr>
114
-
115
- <tr>
116
-
117
- <th scope="row">
118
- <div class="dashicons dashicons-admin-home"></div>
119
- </th>
120
-
121
- <th scope="col">
122
 
123
- <?php if ( Path::get_root() !== $directory ) { ?>
124
 
125
- <a href="<?php echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) ); ?>"><?php echo esc_html( Path::get_root() ); ?></a>
126
- <code>/</code>
 
127
 
128
- <?php $parents = array_filter( explode( '/', str_replace( trailingslashit( Path::get_root() ), '', trailingslashit( dirname( $directory ) ) ) ) );
129
 
130
- foreach ( $parents as $directory_basename ) { ?>
131
 
132
- <a href="<?php echo esc_url( add_query_arg( 'hmbkp_directory_browse', urlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ) ) ); ?>"><?php echo esc_html( $directory_basename ); ?></a>
133
  <code>/</code>
134
 
135
- <?php } ?>
136
-
137
- <?php echo esc_html( basename( $directory ) ); ?>
138
 
139
- <?php } else { ?>
140
 
141
- <?php echo esc_html( Path::get_root() ); ?>
 
142
 
143
- <?php } ?>
144
 
145
- </th>
146
 
147
- <td class="column-filesize">
148
 
149
- <?php if ( Site_Size::is_site_size_being_calculated() ) { ?>
150
 
151
- <span class="spinner is-active"></span>
152
 
153
- <?php } else {
154
 
155
- $root = new \SplFileInfo( Path::get_root() );
156
 
157
- $size = $site_size->filesize( $root );
158
 
159
- if ( false !== $size ) {
160
 
161
- $size = size_format( $size );
162
 
163
- if ( ! $size ) {
164
- $size = '0 B';
165
- } ?>
166
 
167
- <code>
168
 
169
- <?php echo esc_html( $size ); ?>
170
 
171
- <a class="dashicons dashicons-update"
172
- href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( Path::get_root() ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php _e( 'Refresh', 'backupwordpress' ); ?></span></a>
173
 
174
- </code>
 
 
175
 
 
176
 
177
- <?php } ?>
178
 
179
- <?php } ?>
 
180
 
181
- <td>
182
- <?php echo esc_html( substr( sprintf( '%o', fileperms( Path::get_root() ) ), - 4 ) ); ?>
183
- </td>
184
 
185
- <td>
186
 
187
- <?php if ( is_link( Path::get_root() ) ) {
188
 
189
- _e( 'Symlink', 'backupwordpress' );
190
 
191
- } elseif ( is_dir( Path::get_root() ) ) {
 
 
192
 
193
- _e( 'Folder', 'backupwordpress' );
194
 
195
- } ?>
 
 
 
 
196
 
197
- </td>
198
 
199
- <td></td>
200
 
201
- </tr>
202
 
203
  </thead>
204
 
@@ -244,18 +239,15 @@ $user_excludes = $excludes->get_user_excludes(); ?>
244
 
245
  <?php if ( $is_unreadable ) { ?>
246
 
247
- <code class="strikethrough"
248
- title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
249
 
250
  <?php } elseif ( $file->isFile() ) { ?>
251
 
252
- <code
253
- title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
254
 
255
  <?php } elseif ( $file->isDir() ) { ?>
256
 
257
- <code title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><a
258
- href="<?php echo esc_url( add_query_arg( 'hmbkp_directory_browse', urlencode( wp_normalize_path( $file->getPathname() ) ) ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></a></code>
259
 
260
  <?php } ?>
261
 
@@ -284,11 +276,7 @@ $user_excludes = $excludes->get_user_excludes(); ?>
284
  <?php echo esc_html( $size ); ?>
285
 
286
  <?php if ( $file->isDir() ) { ?>
287
-
288
- <a title="<?php _e( 'Recalculate the size of this directory', 'backupwordpress' ); ?>"
289
- class="dashicons dashicons-update"
290
- href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( wp_normalize_path( $file->getPathname() ) ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php _e( 'Refresh', 'backupwordpress' ); ?></span></a>
291
-
292
  <?php } ?>
293
 
294
  </code>
@@ -303,24 +291,21 @@ $user_excludes = $excludes->get_user_excludes(); ?>
303
  </td>
304
 
305
  <td>
306
- <?php echo esc_html( substr( sprintf( '%o', $file->getPerms() ), - 4 ) ); ?>
 
 
307
  </td>
308
 
309
  <td>
310
 
311
  <?php if ( $file->isLink() ) { ?>
312
 
313
- <span
314
- title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php _e( 'Symlink', 'backupwordpress' ); ?></span>
315
 
316
  <?php } elseif ( $file->isDir() ) {
317
-
318
  _e( 'Folder', 'backupwordpress' );
319
-
320
  } else {
321
-
322
  _e( 'File', 'backupwordpress' );
323
-
324
  } ?>
325
 
326
  </td>
@@ -329,8 +314,7 @@ $user_excludes = $excludes->get_user_excludes(); ?>
329
 
330
  <?php if ( $is_unreadable ) { ?>
331
 
332
- <strong
333
- title="<?php _e( 'Unreadable files won\'t be backed up.', 'backupwordpress' ); ?>"><?php _e( 'Unreadable', 'backupwordpress' ); ?></strong>
334
 
335
  <?php } elseif ( $is_excluded ) { ?>
336
 
@@ -348,7 +332,7 @@ $user_excludes = $excludes->get_user_excludes(); ?>
348
  <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array(
349
  'hmbkp_schedule_id' => $schedule->get_id(),
350
  'action' => 'hmbkp_add_exclude_rule',
351
- 'hmbkp_exclude_pathname' => urlencode( $exclude_path )
352
  ), admin_url( 'admin-post.php' ) ), 'hmbkp-add-exclude-rule', 'hmbkp-add-exclude-rule-nonce' ) ); ?>"
353
  class="button-secondary"><?php _e( 'Exclude &rarr;', 'backupwordpress' ); ?></a>
354
 
@@ -374,8 +358,7 @@ $user_excludes = $excludes->get_user_excludes(); ?>
374
 
375
 
376
  <p class="submit">
377
- <a href="<?php echo esc_url( get_settings_url() ) ?>"
378
- class="button-primary"><?php _e( 'Done', 'backupwordpress' ); ?></a>
379
  </p>
380
 
381
  </div>
57
 
58
  <a href="<?php echo admin_action_url( 'remove_exclude_rule', array(
59
  'hmbkp_remove_exclude' => $exclude,
60
+ 'hmbkp_schedule_id' => $schedule->get_id(),
61
  ) ); ?>" class="delete-action"><?php _e( 'Stop excluding', 'backupwordpress' ); ?></a>
62
 
63
  <?php endif; ?>
89
  if ( false !== strpos( $untrusted_directory, Path::get_root() ) && is_dir( $untrusted_directory ) ) {
90
  $directory = $untrusted_directory;
91
  }
 
92
  }
93
 
94
  $exclude_string = implode( '|', $excludes->get_excludes_for_regex() );
102
 
103
  <thead>
104
 
105
+ <tr>
106
+ <th></th>
107
+ <th scope="col"><?php _e( 'Name', 'backupwordpress' ); ?></th>
108
+ <th scope="col" class="column-format"><?php _e( 'Size', 'backupwordpress' ); ?></th>
109
+ <th scope="col" class="column-format"><?php _e( 'Permissions', 'backupwordpress' ); ?></th>
110
+ <th scope="col" class="column-format"><?php _e( 'Type', 'backupwordpress' ); ?></th>
111
+ <th scope="col" class="column-format"><?php _e( 'Status', 'backupwordpress' ); ?></th>
112
+ </tr>
 
 
 
 
 
 
 
 
113
 
114
+ <tr>
115
 
116
+ <th scope="row">
117
+ <div class="dashicons dashicons-admin-home"></div>
118
+ </th>
119
 
120
+ <th scope="col">
121
 
122
+ <?php if ( Path::get_root() !== $directory ) { ?>
123
 
124
+ <a href="<?php echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) ); ?>"><?php echo esc_html( Path::get_root() ); ?></a>
125
  <code>/</code>
126
 
127
+ <?php $parents = array_filter( explode( '/', str_replace( trailingslashit( Path::get_root() ), '', trailingslashit( dirname( $directory ) ) ) ) );
 
 
128
 
129
+ foreach ( $parents as $directory_basename ) { ?>
130
 
131
+ <a href="<?php echo esc_url( add_query_arg( 'hmbkp_directory_browse', urlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ) ) ); ?>"><?php echo esc_html( $directory_basename ); ?></a>
132
+ <code>/</code>
133
 
134
+ <?php } ?>
135
 
136
+ <?php echo esc_html( basename( $directory ) ); ?>
137
 
138
+ <?php } else { ?>
139
 
140
+ <?php echo esc_html( Path::get_root() ); ?>
141
 
142
+ <?php } ?>
143
 
144
+ </th>
145
 
146
+ <td class="column-filesize">
147
 
148
+ <?php if ( Site_Size::is_site_size_being_calculated() ) { ?>
149
 
150
+ <span class="spinner is-active"></span>
151
 
152
+ <?php } else {
153
 
154
+ $root = new \SplFileInfo( Path::get_root() );
 
 
155
 
156
+ $size = $site_size->filesize( $root );
157
 
158
+ if ( false !== $size ) {
159
 
160
+ $size = size_format( $size );
 
161
 
162
+ if ( ! $size ) {
163
+ $size = '0 B';
164
+ } ?>
165
 
166
+ <code>
167
 
168
+ <?php echo esc_html( $size ); ?>
169
 
170
+ <a class="dashicons dashicons-update"
171
+ href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( Path::get_root() ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php _e( 'Refresh', 'backupwordpress' ); ?></span></a>
172
 
173
+ </code>
 
 
174
 
 
175
 
176
+ <?php } ?>
177
 
178
+ <?php } ?>
179
 
180
+ <td>
181
+ <?php echo esc_html( substr( sprintf( '%o', fileperms( Path::get_root() ) ), - 4 ) ); ?>
182
+ </td>
183
 
184
+ <td>
185
 
186
+ <?php if ( is_link( Path::get_root() ) ) {
187
+ _e( 'Symlink', 'backupwordpress' );
188
+ } elseif ( is_dir( Path::get_root() ) ) {
189
+ _e( 'Folder', 'backupwordpress' );
190
+ } ?>
191
 
192
+ </td>
193
 
194
+ <td></td>
195
 
196
+ </tr>
197
 
198
  </thead>
199
 
239
 
240
  <?php if ( $is_unreadable ) { ?>
241
 
242
+ <code class="strikethrough" title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
 
243
 
244
  <?php } elseif ( $file->isFile() ) { ?>
245
 
246
+ <code title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
 
247
 
248
  <?php } elseif ( $file->isDir() ) { ?>
249
 
250
+ <code title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><a href="<?php echo esc_url( add_query_arg( 'hmbkp_directory_browse', urlencode( wp_normalize_path( $file->getPathname() ) ) ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></a></code>
 
251
 
252
  <?php } ?>
253
 
276
  <?php echo esc_html( $size ); ?>
277
 
278
  <?php if ( $file->isDir() ) { ?>
279
+ <a title="<?php _e( 'Recalculate the size of this directory', 'backupwordpress' ); ?>" class="dashicons dashicons-update" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( wp_normalize_path( $file->getPathname() ) ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php _e( 'Refresh', 'backupwordpress' ); ?></span></a>
 
 
 
 
280
  <?php } ?>
281
 
282
  </code>
291
  </td>
292
 
293
  <td>
294
+ <?php if ( ! $is_unreadable ) {
295
+ echo esc_html( substr( sprintf( '%o', $file->getPerms() ), - 4 ) );
296
+ } ?>
297
  </td>
298
 
299
  <td>
300
 
301
  <?php if ( $file->isLink() ) { ?>
302
 
303
+ <span title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php _e( 'Symlink', 'backupwordpress' ); ?></span>
 
304
 
305
  <?php } elseif ( $file->isDir() ) {
 
306
  _e( 'Folder', 'backupwordpress' );
 
307
  } else {
 
308
  _e( 'File', 'backupwordpress' );
 
309
  } ?>
310
 
311
  </td>
314
 
315
  <?php if ( $is_unreadable ) { ?>
316
 
317
+ <strong title="<?php _e( 'Unreadable files won\'t be backed up.', 'backupwordpress' ); ?>"><?php _e( 'Unreadable', 'backupwordpress' ); ?></strong>
 
318
 
319
  <?php } elseif ( $is_excluded ) { ?>
320
 
332
  <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array(
333
  'hmbkp_schedule_id' => $schedule->get_id(),
334
  'action' => 'hmbkp_add_exclude_rule',
335
+ 'hmbkp_exclude_pathname' => urlencode( $exclude_path ),
336
  ), admin_url( 'admin-post.php' ) ), 'hmbkp-add-exclude-rule', 'hmbkp-add-exclude-rule-nonce' ) ); ?>"
337
  class="button-secondary"><?php _e( 'Exclude &rarr;', 'backupwordpress' ); ?></a>
338
 
358
 
359
 
360
  <p class="submit">
361
+ <a href="<?php echo esc_url( get_settings_url() ) ?>" class="button-primary"><?php _e( 'Done', 'backupwordpress' ); ?></a>
 
362
  </p>
363
 
364
  </div>
admin/schedule-form.php CHANGED
@@ -183,7 +183,7 @@ clear_settings_errors();
183
 
184
  $site_size = new Site_Size;
185
 
186
- if ( Site_Size::is_site_size_cached() ) {
187
  printf( __( 'This schedule will store a maximum of %s of backups.', 'backupwordpress' ), '<code>' . esc_html( size_format( $site_size->get_site_size( $schedule->get_type(), $schedule->get_excludes() ) * $schedule->get_max_backups() ) ) . '</code>' );
188
  } ?>
189
 
183
 
184
  $site_size = new Site_Size;
185
 
186
+ if ( $site_size->is_site_size_cached() ) {
187
  printf( __( 'This schedule will store a maximum of %s of backups.', 'backupwordpress' ), '<code>' . esc_html( size_format( $site_size->get_site_size( $schedule->get_type(), $schedule->get_excludes() ) * $schedule->get_max_backups() ) ) . '</code>' );
188
  } ?>
189
 
backupwordpress.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: BackUpWordPress
4
  Plugin URI: http://bwp.hmn.md/
5
  Description: Simple automated backups of your WordPress powered website. Once activated you'll find me under <strong>Tools &rarr; Backups</strong>. On multisite, you'll find me under the Network Settings menu.
6
- Version: 3.4.5
7
  Author: Human Made Limited
8
  Author URI: http://hmn.md/
9
  License: GPL-2+
3
  Plugin Name: BackUpWordPress
4
  Plugin URI: http://bwp.hmn.md/
5
  Description: Simple automated backups of your WordPress powered website. Once activated you'll find me under <strong>Tools &rarr; Backups</strong>. On multisite, you'll find me under the Network Settings menu.
6
+ Version: 3.5-beta
7
  Author: Human Made Limited
8
  Author URI: http://hmn.md/
9
  License: GPL-2+
classes/backup/class-backup-engine-database-mysqldump.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace HM\BackUpWordPress;
4
 
 
 
5
  /**
6
  * Perform a database backup using the mysqldump cli command
7
  */
@@ -65,7 +67,7 @@ class Mysqldump_Database_Backup_Engine extends Database_Backup_Engine {
65
  '/Program Files/MySQL/MySQL Server 5.1/bin/mysqldump',
66
  '/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump',
67
  '/Program Files/MySQL/MySQL Server 4.1/bin/mysqldump',
68
- '/opt/local/bin/mysqldump'
69
  );
70
 
71
  $this->mysqldump_executable_path = Backup_Utilities::get_executable_path( $paths );
@@ -84,34 +86,28 @@ class Mysqldump_Database_Backup_Engine extends Database_Backup_Engine {
84
  */
85
  public function check_user_can_connect_to_database_via_cli() {
86
 
87
- if ( ! $this->get_mysqldump_executable_path() ) {
88
  return false;
89
  }
90
 
91
  $args = $this->get_mysql_connection_args();
92
-
93
  $args[] = escapeshellarg( $this->get_name() );
94
 
95
  // Quit immediately as we're only interesting in testing the connection
96
  $args[] = '--execute="quit"';
97
 
98
- // Pipe STDERR to STDOUT
99
- $args[] = ' 2>&1';
100
-
101
- $output = $return_status = '';
102
- $args = implode( ' ', $args );
103
- exec( 'mysql ' . $args, $output, $return_status );
104
 
105
- $output = $this->ignore_mysql_password_warning( $output );
 
 
 
 
 
106
 
107
- // If there were errors connecting then track them
108
- if ( $output ) {
109
- if ( $return_status === 0 ) {
110
- $this->warning( __CLASS__, implode( ', ', $output ) );
111
- } else {
112
- $this->error( __CLASS__, implode( ', ', $output ) );
113
- return false;
114
- }
115
  }
116
 
117
  return true;
@@ -129,14 +125,9 @@ class Mysqldump_Database_Backup_Engine extends Database_Backup_Engine {
129
  return false;
130
  }
131
 
132
- $output = $return_status = '';
133
-
134
  // Grab the database connections args
135
  $args = $this->get_mysql_connection_args();
136
 
137
- // We don't want to create a new DB
138
- $args[] = '--no-create-db';
139
-
140
  // Allow lock-tables to be overridden
141
  if ( defined( 'HMBKP_MYSQLDUMP_SINGLE_TRANSACTION' ) && HMBKP_MYSQLDUMP_SINGLE_TRANSACTION ) {
142
  $args[] = '--single-transaction';
@@ -151,20 +142,17 @@ class Mysqldump_Database_Backup_Engine extends Database_Backup_Engine {
151
  // The database we're dumping
152
  $args[] = escapeshellarg( $this->get_name() );
153
 
154
- // Pipe STDERR to STDOUT
155
- $args[] = '2>&1';
156
-
157
- exec( escapeshellcmd( $this->get_mysqldump_executable_path() ) . ' ' . implode( ' ', $args ), $output, $return_status );
158
 
159
- $output = $this->ignore_mysql_password_warning( $output );
 
 
 
 
160
 
161
- // Track any errors
162
- if ( $output ) {
163
- if ( $return_status === 0 ) {
164
- $this->warning( __CLASS__, implode( ', ', $output ) );
165
- } else {
166
- $this->error( __CLASS__, implode( ', ', $output ) );
167
- }
168
  }
169
 
170
  return $this->verify_backup();
@@ -199,17 +187,4 @@ class Mysqldump_Database_Backup_Engine extends Database_Backup_Engine {
199
  return $args;
200
 
201
  }
202
-
203
- private function ignore_mysql_password_warning( $output ) {
204
-
205
- $key = array_search( 'Warning: Using a password on the command line interface can be insecure.', $output );
206
-
207
- if ( $key !== false ) {
208
- unset( $output[ $key ] );
209
- }
210
-
211
- return $output;
212
-
213
- }
214
-
215
  }
2
 
3
  namespace HM\BackUpWordPress;
4
 
5
+ use Symfony\Component\Process\Process as Process;
6
+
7
  /**
8
  * Perform a database backup using the mysqldump cli command
9
  */
67
  '/Program Files/MySQL/MySQL Server 5.1/bin/mysqldump',
68
  '/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump',
69
  '/Program Files/MySQL/MySQL Server 4.1/bin/mysqldump',
70
+ '/opt/local/bin/mysqldump',
71
  );
72
 
73
  $this->mysqldump_executable_path = Backup_Utilities::get_executable_path( $paths );
86
  */
87
  public function check_user_can_connect_to_database_via_cli() {
88
 
89
+ if ( ! function_exists( 'proc_open' ) ) {
90
  return false;
91
  }
92
 
93
  $args = $this->get_mysql_connection_args();
 
94
  $args[] = escapeshellarg( $this->get_name() );
95
 
96
  // Quit immediately as we're only interesting in testing the connection
97
  $args[] = '--execute="quit"';
98
 
99
+ $process = new Process( 'mysql ' . implode( ' ', $args ) );
 
 
 
 
 
100
 
101
+ try {
102
+ $process->run();
103
+ } catch ( \Exception $e ) {
104
+ $this->error( __CLASS__, $e->getMessage() );
105
+ return false;
106
+ }
107
 
108
+ if ( ! $process->isSuccessful() ) {
109
+ $this->error( __CLASS__, $process->getErrorOutput() );
110
+ return false;
 
 
 
 
 
111
  }
112
 
113
  return true;
125
  return false;
126
  }
127
 
 
 
128
  // Grab the database connections args
129
  $args = $this->get_mysql_connection_args();
130
 
 
 
 
131
  // Allow lock-tables to be overridden
132
  if ( defined( 'HMBKP_MYSQLDUMP_SINGLE_TRANSACTION' ) && HMBKP_MYSQLDUMP_SINGLE_TRANSACTION ) {
133
  $args[] = '--single-transaction';
142
  // The database we're dumping
143
  $args[] = escapeshellarg( $this->get_name() );
144
 
145
+ $process = new Process( $this->get_mysqldump_executable_path() . ' ' . implode( ' ', $args ) );
146
+ $process->setTimeout( HOUR_IN_SECONDS );
 
 
147
 
148
+ try {
149
+ $process->run();
150
+ } catch ( \Exception $e ) {
151
+ $this->error( __CLASS__, $e->getMessage() );
152
+ }
153
 
154
+ if ( ! $process->isSuccessful() ) {
155
+ $this->error( __CLASS__, $process->getErrorOutput() );
 
 
 
 
 
156
  }
157
 
158
  return $this->verify_backup();
187
  return $args;
188
 
189
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  }
classes/backup/class-backup-engine-database.php CHANGED
@@ -177,13 +177,10 @@ abstract class Database_Backup_Engine extends Backup_Engine {
177
  if ( ! empty( $maybe_socket ) ) {
178
  $this->socket = substr( $maybe_socket, 1 );
179
  }
180
-
181
  } else {
182
  $this->socket = $port_or_socket;
183
  }
184
-
185
  }
186
-
187
  }
188
 
189
  /**
@@ -197,7 +194,7 @@ abstract class Database_Backup_Engine extends Backup_Engine {
197
  public function verify_backup() {
198
 
199
  // If there are errors delete the database dump file
200
- if ( $this->get_errors( __CLASS__ ) && file_exists( $this->get_backup_filepath() ) ) {
201
  unlink( $this->get_backup_filepath() );
202
  }
203
 
@@ -214,5 +211,4 @@ abstract class Database_Backup_Engine extends Backup_Engine {
214
  return true;
215
 
216
  }
217
-
218
  }
177
  if ( ! empty( $maybe_socket ) ) {
178
  $this->socket = substr( $maybe_socket, 1 );
179
  }
 
180
  } else {
181
  $this->socket = $port_or_socket;
182
  }
 
183
  }
 
184
  }
185
 
186
  /**
194
  public function verify_backup() {
195
 
196
  // If there are errors delete the database dump file
197
+ if ( $this->get_errors( get_called_class() ) && file_exists( $this->get_backup_filepath() ) ) {
198
  unlink( $this->get_backup_filepath() );
199
  }
200
 
211
  return true;
212
 
213
  }
 
214
  }
classes/backup/class-backup-engine-file-zip.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace HM\BackUpWordPress;
4
 
 
 
5
  /**
6
  * Perform a file backup using the zip cli command
7
  */
@@ -48,7 +50,8 @@ class Zip_File_Backup_Engine extends File_Backup_Engine {
48
  $paths = array(
49
  'zip',
50
  '/usr/bin/zip',
51
- '/opt/local/bin/zip'
 
52
  );
53
 
54
  $this->zip_executable_path = Backup_Utilities::get_executable_path( $paths );
@@ -66,7 +69,7 @@ class Zip_File_Backup_Engine extends File_Backup_Engine {
66
  */
67
  public function backup() {
68
 
69
- if ( ! Backup_Utilities::is_exec_available() || ! $this->get_zip_executable_path() ) {
70
  return false;
71
  }
72
 
@@ -84,20 +87,27 @@ class Zip_File_Backup_Engine extends File_Backup_Engine {
84
  $command[] = '-x ' . $this->get_exclude_string();
85
  }
86
 
87
- // Push all output to STDERR
88
- $command[] = '2>&1';
89
-
90
  $command = implode( ' ', $command );
91
- $output = $return_status = 0;
92
 
93
- exec( $command, $output, $return_status );
 
 
 
 
 
 
 
 
 
94
 
95
- // Track any errors
96
- if ( $output ) {
97
- if ( $return_status === 0 ) {
98
- $this->warning( __CLASS__, implode( ', ', $output ) );
99
- } else {
100
- $this->error( __CLASS__, implode( ', ', $output ) );
 
 
101
  }
102
  }
103
 
@@ -125,14 +135,10 @@ class Zip_File_Backup_Engine extends File_Backup_Engine {
125
  // Files don't end with /
126
  if ( ! in_array( substr( $rule, - 1 ), array( '\\', '/' ) ) ) {
127
  $file = true;
128
- }
129
-
130
- // If rule starts with a / then treat as absolute path
131
  elseif ( in_array( substr( $rule, 0, 1 ), array( '\\', '/' ) ) ) {
132
  $absolute = true;
133
- }
134
-
135
- // Otherwise treat as dir fragment
136
  else {
137
  $fragment = true;
138
  }
@@ -153,7 +159,6 @@ class Zip_File_Backup_Engine extends File_Backup_Engine {
153
  if ( $absolute ) {
154
  $rule .= '*';
155
  }
156
-
157
  }
158
 
159
  // Escape shell args for zip command
@@ -162,5 +167,4 @@ class Zip_File_Backup_Engine extends File_Backup_Engine {
162
  return implode( ' -x ', $excludes );
163
 
164
  }
165
-
166
  }
2
 
3
  namespace HM\BackUpWordPress;
4
 
5
+ use Symfony\Component\Process\Process as Process;
6
+
7
  /**
8
  * Perform a file backup using the zip cli command
9
  */
50
  $paths = array(
51
  'zip',
52
  '/usr/bin/zip',
53
+ '/usr/local/bin/zip',
54
+ '/opt/local/bin/zip',
55
  );
56
 
57
  $this->zip_executable_path = Backup_Utilities::get_executable_path( $paths );
69
  */
70
  public function backup() {
71
 
72
+ if ( ! $this->get_zip_executable_path() ) {
73
  return false;
74
  }
75
 
87
  $command[] = '-x ' . $this->get_exclude_string();
88
  }
89
 
 
 
 
90
  $command = implode( ' ', $command );
 
91
 
92
+ $process = new Process( $command );
93
+ $process->setTimeout( HOUR_IN_SECONDS );
94
+
95
+ try {
96
+ $process->run();
97
+ } catch ( \Exception $e ) {
98
+ $this->error( __CLASS__, $e->getMessage() );
99
+ }
100
+
101
+ if ( ! $process->isSuccessful() ) {
102
 
103
+ /**
104
+ * Exit Code 18 is returned when an unreadable file is encountered during the zip process.
105
+ *
106
+ * Given the zip process still completes correctly and the unreadable file is simple skipped
107
+ * we don't want to treat 18 as an actual error.
108
+ */
109
+ if ( $process->getExitCode() !== 18 ) {
110
+ $this->error( __CLASS__, $process->getErrorOutput() );
111
  }
112
  }
113
 
135
  // Files don't end with /
136
  if ( ! in_array( substr( $rule, - 1 ), array( '\\', '/' ) ) ) {
137
  $file = true;
138
+ } // If rule starts with a / then treat as absolute path
 
 
139
  elseif ( in_array( substr( $rule, 0, 1 ), array( '\\', '/' ) ) ) {
140
  $absolute = true;
141
+ } // Otherwise treat as dir fragment
 
 
142
  else {
143
  $fragment = true;
144
  }
159
  if ( $absolute ) {
160
  $rule .= '*';
161
  }
 
162
  }
163
 
164
  // Escape shell args for zip command
167
  return implode( ' -x ', $excludes );
168
 
169
  }
 
170
  }
classes/backup/class-backup-engine-file.php CHANGED
@@ -96,7 +96,7 @@ abstract class File_Backup_Engine extends Backup_Engine {
96
  public function verify_backup() {
97
 
98
  // If there are errors delete the backup file.
99
- if ( $this->get_errors( __CLASS__ ) && file_exists( $this->get_backup_filepath() ) ) {
100
  unlink( $this->get_backup_filepath() );
101
  }
102
 
@@ -108,5 +108,4 @@ abstract class File_Backup_Engine extends Backup_Engine {
108
  return true;
109
 
110
  }
111
-
112
  }
96
  public function verify_backup() {
97
 
98
  // If there are errors delete the backup file.
99
+ if ( $this->get_errors( get_called_class() ) && file_exists( $this->get_backup_filepath() ) ) {
100
  unlink( $this->get_backup_filepath() );
101
  }
102
 
108
  return true;
109
 
110
  }
 
111
  }
classes/backup/class-backup-utilities.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace HM\BackUpWordPress;
4
 
 
 
5
  /**
6
  * A set of Backup Utility functions
7
  */
@@ -28,66 +30,6 @@ class Backup_Utilities {
28
 
29
  }
30
 
31
- /**
32
- * Check whether it's possible to use `exec`.
33
- *
34
- * @return boolean [description]
35
- */
36
- public static function is_exec_available() {
37
-
38
- // You can't use exec if Safe Mode is on.
39
- if ( self::is_safe_mode_on() ) {
40
- return false;
41
- }
42
-
43
- // Check if exec is specifically disabled
44
- if ( self::is_function_disabled( 'exec' ) ) {
45
- return false;
46
- }
47
-
48
- // Some servers seem to disable escapeshellcmd / escapeshellarg separately to exec, in
49
- // that instance we don't want to use exec as it's insecure
50
- if ( self::is_function_disabled( 'escapeshellcmd' ) || self::is_function_disabled( 'escapeshellarg' ) ) {
51
- return false;
52
- }
53
-
54
- // Can we issue a simple echo command?
55
- exec( 'echo backupwordpress', $output, $return );
56
-
57
- if ( $return !== 0 ) {
58
- return false;
59
- }
60
-
61
- return true;
62
-
63
- }
64
-
65
- /**
66
- * Check whether a PHP function has been disabled.
67
- *
68
- * @param string $function The function you want to test for.
69
- * @param string $ini_get_callback By default we check with ini_get, but
70
- * it's possible to overridde this for
71
- * testing purposes.
72
- *
73
- * @return boolean Whether the function is disabled or not.
74
- */
75
- public static function is_function_disabled( $function, $ini_get_callback = 'ini_get' ) {
76
-
77
- // Suhosin stores it's disabled functions in `suhosin.executor.func.blacklist`
78
- $suhosin_blacklist = array_map( 'trim', explode( ',', @call_user_func( $ini_get_callback, 'suhosin.executor.func.blacklist' ) ) );
79
-
80
- // PHP supports disabling functions by adding them to `disable_functions` in php.ini.
81
- $disabled_functions = array_map( 'trim', explode( ',', @call_user_func( $ini_get_callback, 'disable_functions' ) ) );
82
-
83
- if ( in_array( $function, array_merge( $suhosin_blacklist, $disabled_functions ) ) ) {
84
- return true;
85
- }
86
-
87
- return false;
88
-
89
- }
90
-
91
  /**
92
  * Attempt to work out path to a cli executable.
93
  *
@@ -97,7 +39,7 @@ class Backup_Utilities {
97
  */
98
  public static function get_executable_path( $paths ) {
99
 
100
- if ( ! self::is_exec_available() ) {
101
  return false;
102
  }
103
 
@@ -105,25 +47,24 @@ class Backup_Utilities {
105
 
106
  foreach ( $paths as $path ) {
107
 
108
- $output = $result = 0;
109
-
110
  /**
111
  * Attempt to call `--version` on each path, the one which works
112
  * must be the correct path.
113
- *
114
- * We pipe STDERR to /dev/null so we don't leak errors.
115
  */
116
- exec( escapeshellarg( $path ) . ' --version ' . ignore_stderr(), $output, $result );
117
 
118
- // If the command executed successfully then this must be the correct path
119
- if ( $result === 0 ) {
120
- return $path;
 
121
  }
122
 
 
 
 
123
  }
124
 
125
  return false;
126
 
127
  }
128
-
129
  }
2
 
3
  namespace HM\BackUpWordPress;
4
 
5
+ use Symfony\Component\Process\Process as Process;
6
+
7
  /**
8
  * A set of Backup Utility functions
9
  */
30
 
31
  }
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  /**
34
  * Attempt to work out path to a cli executable.
35
  *
39
  */
40
  public static function get_executable_path( $paths ) {
41
 
42
+ if ( ! function_exists( 'proc_open' ) ) {
43
  return false;
44
  }
45
 
47
 
48
  foreach ( $paths as $path ) {
49
 
 
 
50
  /**
51
  * Attempt to call `--version` on each path, the one which works
52
  * must be the correct path.
 
 
53
  */
54
+ $process = new Process( $path . ' --version' );
55
 
56
+ try {
57
+ $process->run();
58
+ } catch ( \Exception $e ) {
59
+ return false;
60
  }
61
 
62
+ if ( $process->isSuccessful() ) {
63
+ return $path;
64
+ }
65
  }
66
 
67
  return false;
68
 
69
  }
 
70
  }
classes/backup/class-backup.php CHANGED
@@ -85,7 +85,7 @@ class Backup {
85
  // Set the file backup engine settings
86
  foreach( $file_backup_engines as &$backup_engine ) {
87
  $backup_engine->set_backup_filename( $this->backup_filename );
88
- $backup_engine->set_excludes( new Excludes( array( '*.zip', 'index.html', '.htaccess', '.*-running' ) ) );
89
  }
90
 
91
  // Zip up the database dump
@@ -182,6 +182,16 @@ class Backup {
182
 
183
  }
184
 
 
 
 
 
 
 
 
 
 
 
185
  public function get_database_backup_filepath() {
186
  return $this->database_dump_filepath;
187
  }
85
  // Set the file backup engine settings
86
  foreach( $file_backup_engines as &$backup_engine ) {
87
  $backup_engine->set_backup_filename( $this->backup_filename );
88
+ $backup_engine->set_excludes( new Excludes( array( '*.zip', 'index.html', '.htaccess', '.*-running', '.files' ) ) );
89
  }
90
 
91
  // Zip up the database dump
182
 
183
  }
184
 
185
+ /**
186
+ * Back compat with old error mathod
187
+ *
188
+ * @deprecated 3.4 Backup->warning( $context, $warning )
189
+ */
190
+ public function error( $context, $message ) {
191
+ _deprecated_function( __FUNCTION__, '3.4', 'Backup->warning( $context, $warning )' );
192
+ $this->warning( $context, $message );
193
+ }
194
+
195
  public function get_database_backup_filepath() {
196
  return $this->database_dump_filepath;
197
  }
classes/class-path.php CHANGED
@@ -101,7 +101,7 @@ class Path {
101
  return wp_normalize_path( HMBKP_ROOT );
102
  }
103
 
104
- $home_path = $site_path;
105
 
106
  if ( path_in_php_open_basedir( dirname( $site_path ) ) ) {
107
 
@@ -110,7 +110,7 @@ class Path {
110
  if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
111
  $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
112
  $pos = strripos( wp_normalize_path( $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
113
- $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
114
  $home_path = trailingslashit( $home_path );
115
  }
116
 
@@ -456,6 +456,11 @@ class CleanUpIterator extends \FilterIterator {
456
  return false;
457
  }
458
 
 
 
 
 
 
459
  // Don't cleanup the backup running file
460
  return ! preg_match( '/(.*-running)/', $this->current() );
461
 
101
  return wp_normalize_path( HMBKP_ROOT );
102
  }
103
 
104
+ $home_path = wp_normalize_path( $site_path );
105
 
106
  if ( path_in_php_open_basedir( dirname( $site_path ) ) ) {
107
 
110
  if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) {
111
  $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */
112
  $pos = strripos( wp_normalize_path( $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
113
+ $home_path = substr( wp_normalize_path( $_SERVER['SCRIPT_FILENAME'] ), 0, $pos );
114
  $home_path = trailingslashit( $home_path );
115
  }
116
 
456
  return false;
457
  }
458
 
459
+ // Don't remove the file manifest
460
+ if ( '.files' === $this->current()->getBasename() ) {
461
+ return false;
462
+ }
463
+
464
  // Don't cleanup the backup running file
465
  return ! preg_match( '/(.*-running)/', $this->current() );
466
 
classes/class-plugin.php CHANGED
@@ -6,7 +6,7 @@ namespace HM\BackUpWordPress;
6
  * Class Plugin
7
  */
8
  final class Plugin {
9
- const PLUGIN_VERSION = '3.4.5';
10
 
11
  /**
12
  * @var Plugin The singleton instance.
6
  * Class Plugin
7
  */
8
  final class Plugin {
9
+ const PLUGIN_VERSION = '3.5-beta';
10
 
11
  /**
12
  * @var Plugin The singleton instance.
classes/class-requirement.php CHANGED
@@ -32,8 +32,9 @@ abstract class Requirement {
32
 
33
  $test = $this->test();
34
 
35
- if ( is_string( $test ) && $test )
36
  return $test;
 
37
 
38
  if ( is_bool( $test ) || empty( $test ) ) {
39
 
@@ -52,7 +53,6 @@ abstract class Requirement {
52
  public function raw_result() {
53
  return $this->test();
54
  }
55
-
56
  }
57
 
58
  /**
@@ -77,38 +77,9 @@ class Requirement_Zip_Archive extends Requirement {
77
  return false;
78
 
79
  }
80
-
81
  }
82
  Requirements::register( 'HM\BackUpWordPress\Requirement_Zip_Archive', 'PHP' );
83
 
84
- /**
85
- * Class Requirement_Directory_Iterator_Follow_Symlinks
86
- *
87
- * Tests whether the FOLLOW_SYMLINKS class constant is available on Directory Iterator
88
- */
89
- class Requirement_Directory_Iterator_Follow_Symlinks extends Requirement {
90
-
91
- /**
92
- * @var string
93
- */
94
- var $name = 'DirectoryIterator FOLLOW_SYMLINKS';
95
-
96
- /**
97
- * @return bool
98
- */
99
- public static function test() {
100
-
101
- if ( defined( 'RecursiveDirectoryIterator::FOLLOW_SYMLINKS' ) ) {
102
- return true;
103
- }
104
-
105
- return false;
106
-
107
- }
108
-
109
- }
110
- Requirements::register( 'HM\BackUpWordPress\Requirement_Directory_Iterator_Follow_Symlinks', 'PHP' );
111
-
112
  /**
113
  * Class Requirement_Zip_Command
114
  *
@@ -131,7 +102,6 @@ class Requirement_Zip_Command_Path extends Requirement {
131
  return $backup->get_zip_executable_path();
132
 
133
  }
134
-
135
  }
136
  Requirements::register( 'HM\BackUpWordPress\Requirement_Zip_Command_Path', 'Server' );
137
 
@@ -157,62 +127,9 @@ class Requirement_Mysqldump_Command_Path extends Requirement {
157
  return $backup->get_mysqldump_executable_path();
158
 
159
  }
160
-
161
  }
162
  Requirements::register( 'HM\BackUpWordPress\Requirement_Mysqldump_Command_Path', 'Server' );
163
 
164
- /**
165
- * Class Requirement_PHP_User
166
- */
167
- class Requirement_PHP_User extends Requirement {
168
-
169
- /**
170
- * @var string
171
- */
172
- var $name = 'User';
173
-
174
- /**
175
- * @return string
176
- */
177
- public static function test() {
178
-
179
- if ( ! Backup_Utilities::is_exec_available() ) {
180
- return '';
181
- }
182
-
183
- return shell_exec( 'whoami' );
184
-
185
- }
186
-
187
- }
188
- Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_User', 'PHP' );
189
-
190
- /**
191
- * Class Requirement_PHP_Group
192
- */
193
- class Requirement_PHP_Group extends Requirement {
194
-
195
- /**
196
- * @var string
197
- */
198
- var $name = 'Group[s]';
199
-
200
- /**
201
- * @return string
202
- */
203
- public static function test() {
204
-
205
- if ( ! Backup_Utilities::is_exec_available() ) {
206
- return '';
207
- }
208
-
209
- return shell_exec( 'groups' );
210
-
211
- }
212
-
213
- }
214
- Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Group', 'PHP' );
215
-
216
  /**
217
  * Class Requirement_PHP_Version
218
  */
@@ -229,7 +146,6 @@ class Requirement_PHP_Version extends Requirement {
229
  public static function test() {
230
  return PHP_VERSION;
231
  }
232
-
233
  }
234
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Version', 'PHP' );
235
 
@@ -257,7 +173,6 @@ class Requirement_Cron_Array extends Requirement {
257
  return $cron;
258
 
259
  }
260
-
261
  }
262
  Requirements::register( 'HM\BackUpWordPress\Requirement_Cron_Array', 'Site' );
263
 
@@ -290,7 +205,6 @@ class Requirement_Language extends Requirement {
290
  return 'en_US';
291
 
292
  }
293
-
294
  }
295
  Requirements::register( 'HM\BackUpWordPress\Requirement_Language', 'Site' );
296
 
@@ -310,30 +224,9 @@ class Requirement_Safe_Mode extends Requirement {
310
  public static function test() {
311
  return Backup_Utilities::is_safe_mode_on();
312
  }
313
-
314
  }
315
  Requirements::register( 'HM\BackUpWordPress\Requirement_Safe_Mode', 'PHP' );
316
 
317
- /**
318
- * Class Requirement_Shell_Exec
319
- */
320
- class Requirement_Exec extends Requirement {
321
-
322
- /**
323
- * @var string
324
- */
325
- var $name = 'Exec';
326
-
327
- /**
328
- * @return bool
329
- */
330
- public static function test() {
331
- return Backup_Utilities::is_exec_available();
332
- }
333
-
334
- }
335
- Requirements::register( 'HM\BackUpWordPress\Requirement_Exec', 'PHP' );
336
-
337
  /**
338
  * Class Requirement_Memory_Limit
339
  */
@@ -350,7 +243,6 @@ class Requirement_PHP_Memory_Limit extends Requirement {
350
  public static function test() {
351
  return @ini_get( 'memory_limit' );
352
  }
353
-
354
  }
355
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Memory_Limit', 'PHP' );
356
 
@@ -370,7 +262,6 @@ class Requirement_Backup_Path extends Requirement {
370
  public static function test() {
371
  return Path::get_path();
372
  }
373
-
374
  }
375
  Requirements::register( 'HM\BackUpWordPress\Requirement_Backup_Path', 'Site' );
376
 
@@ -390,7 +281,6 @@ class Requirement_Backup_Path_Permissions extends Requirement {
390
  public static function test() {
391
  return substr( sprintf( '%o', fileperms( Path::get_path() ) ), - 4 );
392
  }
393
-
394
  }
395
  Requirements::register( 'HM\BackUpWordPress\Requirement_Backup_Path_Permissions', 'Site' );
396
 
@@ -410,7 +300,6 @@ class Requirement_WP_CONTENT_DIR extends Requirement {
410
  public static function test() {
411
  return WP_CONTENT_DIR;
412
  }
413
-
414
  }
415
  Requirements::register( 'HM\BackUpWordPress\Requirement_WP_CONTENT_DIR', 'Site' );
416
 
@@ -430,7 +319,6 @@ class Requirement_WP_CONTENT_DIR_Permissions extends Requirement {
430
  public static function test() {
431
  return substr( sprintf( '%o', fileperms( WP_CONTENT_DIR ) ), - 4 );
432
  }
433
-
434
  }
435
  Requirements::register( 'HM\BackUpWordPress\Requirement_WP_CONTENT_DIR_Permissions', 'Site' );
436
 
@@ -450,7 +338,6 @@ class Requirement_ABSPATH extends Requirement {
450
  public static function test() {
451
  return ABSPATH;
452
  }
453
-
454
  }
455
  Requirements::register( 'HM\BackUpWordPress\Requirement_ABSPATH', 'Site' );
456
 
@@ -470,7 +357,6 @@ class Requirement_Backup_Root_Path extends Requirement {
470
  public static function test() {
471
  return Path::get_root();
472
  }
473
-
474
  }
475
  Requirements::register( 'HM\BackUpWordPress\Requirement_Backup_Root_Path', 'Site' );
476
 
@@ -500,13 +386,11 @@ class Requirement_Calculated_Size extends Requirement {
500
  if ( $site_size->is_site_size_cached() ) {
501
  $backup_sizes[ $schedule->get_type() ] = $site_size->get_formatted_site_size();
502
  }
503
-
504
  }
505
 
506
  return $backup_sizes;
507
 
508
  }
509
-
510
  }
511
  Requirements::register( 'HM\BackUpWordPress\Requirement_Calculated_Size', 'Site' );
512
 
@@ -526,7 +410,6 @@ class Requirement_WP_Cron_Test extends Requirement {
526
  public static function test() {
527
  return (bool) get_option( 'hmbkp_wp_cron_test_failed' );
528
  }
529
-
530
  }
531
  Requirements::register( 'HM\BackUpWordPress\Requirement_WP_Cron_Test', 'Site' );
532
 
@@ -546,7 +429,6 @@ class Requirement_PHP_API extends Requirement {
546
  public static function test() {
547
  return php_sapi_name();
548
  }
549
-
550
  }
551
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_API', 'PHP' );
552
 
@@ -565,13 +447,13 @@ class Requirement_Server_Software extends Requirement {
565
  */
566
  public static function test() {
567
 
568
- if ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) )
569
  return $_SERVER['SERVER_SOFTWARE'];
 
570
 
571
  return false;
572
 
573
  }
574
-
575
  }
576
  Requirements::register( 'HM\BackUpWordPress\Requirement_Server_Software', 'Server' );
577
 
@@ -591,7 +473,6 @@ class Requirement_Server_OS extends Requirement {
591
  public static function test() {
592
  return PHP_OS;
593
  }
594
-
595
  }
596
  Requirements::register( 'HM\BackUpWordPress\Requirement_Server_OS', 'Server' );
597
 
@@ -611,7 +492,6 @@ class Requirement_PHP_Disable_Functions extends Requirement {
611
  public static function test() {
612
  return @ini_get( 'disable_functions' );
613
  }
614
-
615
  }
616
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Disable_Functions', 'PHP' );
617
 
@@ -631,7 +511,6 @@ class Requirement_PHP_Open_Basedir extends Requirement {
631
  public static function test() {
632
  return @ini_get( 'open_basedir' );
633
  }
634
-
635
  }
636
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Open_Basedir', 'PHP' );
637
 
@@ -653,7 +532,6 @@ class Requirement_Define_HMBKP_PATH extends Requirement {
653
  public static function test() {
654
  return defined( 'HMBKP_PATH' ) ? HMBKP_PATH : '';
655
  }
656
-
657
  }
658
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_PATH', 'constants' );
659
 
@@ -673,7 +551,6 @@ class Requirement_Define_HMBKP_ROOT extends Requirement {
673
  public static function test() {
674
  return defined( 'HMBKP_ROOT' ) ? HMBKP_ROOT : '';
675
  }
676
-
677
  }
678
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_ROOT', 'constants' );
679
 
@@ -693,7 +570,6 @@ class Requirement_Define_HMBKP_MYSQLDUMP_PATH extends Requirement {
693
  public static function test() {
694
  return defined( 'HMBKP_MYSQLDUMP_PATH' ) ? HMBKP_MYSQLDUMP_PATH : '';
695
  }
696
-
697
  }
698
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_MYSQLDUMP_PATH', 'constants' );
699
 
@@ -713,7 +589,6 @@ class Requirement_Define_HMBKP_ZIP_PATH extends Requirement {
713
  public static function test() {
714
  return defined( 'HMBKP_ZIP_PATH' ) ? HMBKP_ZIP_PATH : '';
715
  }
716
-
717
  }
718
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_ZIP_PATH', 'constants' );
719
 
@@ -733,7 +608,6 @@ class Requirement_Define_HMBKP_CAPABILITY extends Requirement {
733
  public static function test() {
734
  return defined( 'HMBKP_CAPABILITY' ) ? HMBKP_CAPABILITY : '';
735
  }
736
-
737
  }
738
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_CAPABILITY', 'constants' );
739
 
@@ -753,7 +627,6 @@ class Requirement_Define_HMBKP_EMAIL extends Requirement {
753
  public static function test() {
754
  return defined( 'HMBKP_EMAIL' ) ? HMBKP_EMAIL : '';
755
  }
756
-
757
  }
758
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_EMAIL', 'constants' );
759
 
@@ -773,7 +646,6 @@ class Requirement_Define_HMBKP_ATTACHMENT_MAX_FILESIZE extends Requirement {
773
  public static function test() {
774
  return defined( 'HMBKP_ATTACHMENT_MAX_FILESIZE' ) ? HMBKP_ATTACHMENT_MAX_FILESIZE : '';
775
  }
776
-
777
  }
778
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_ATTACHMENT_MAX_FILESIZE', 'constants' );
779
 
@@ -793,7 +665,6 @@ class Requirement_Define_HMBKP_EXCLUDE extends Requirement {
793
  public static function test() {
794
  return defined( 'HMBKP_EXCLUDE' ) ? HMBKP_EXCLUDE : '';
795
  }
796
-
797
  }
798
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_EXCLUDE', 'constants' );
799
 
@@ -801,10 +672,9 @@ class Requirement_Active_Plugins extends Requirement {
801
 
802
  var $name = 'Active Plugins';
803
 
804
- public static function test(){
805
  return get_option( 'active_plugins' );
806
  }
807
-
808
  }
809
  Requirements::register( 'HM\BackUpWordPress\Requirement_Active_Plugins', 'Site' );
810
 
@@ -812,10 +682,9 @@ class Requirement_Home_Url extends Requirement {
812
 
813
  var $name = 'Home URL';
814
 
815
- public static function test(){
816
  return home_url();
817
  }
818
-
819
  }
820
  Requirements::register( 'HM\BackUpWordPress\Requirement_Home_Url', 'Site' );
821
 
@@ -826,7 +695,6 @@ class Requirement_Site_Url extends Requirement {
826
  public static function test() {
827
  return site_url();
828
  }
829
-
830
  }
831
  Requirements::register( 'HM\BackUpWordPress\Requirement_Site_Url', 'Site' );
832
 
@@ -843,7 +711,7 @@ class Requirement_Max_Exec extends Requirement {
843
 
844
  var $name = 'Max execution time';
845
 
846
- public static function test(){
847
  return @ini_get( 'max_execution_time' );
848
  }
849
  }
@@ -863,4 +731,24 @@ class Requirement_PDO extends Requirement {
863
 
864
  }
865
  }
 
866
  Requirements::register( 'HM\BackUpWordPress\Requirement_PDO', 'PHP' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  $test = $this->test();
34
 
35
+ if ( is_string( $test ) && $test ) {
36
  return $test;
37
+ }
38
 
39
  if ( is_bool( $test ) || empty( $test ) ) {
40
 
53
  public function raw_result() {
54
  return $this->test();
55
  }
 
56
  }
57
 
58
  /**
77
  return false;
78
 
79
  }
 
80
  }
81
  Requirements::register( 'HM\BackUpWordPress\Requirement_Zip_Archive', 'PHP' );
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  /**
84
  * Class Requirement_Zip_Command
85
  *
102
  return $backup->get_zip_executable_path();
103
 
104
  }
 
105
  }
106
  Requirements::register( 'HM\BackUpWordPress\Requirement_Zip_Command_Path', 'Server' );
107
 
127
  return $backup->get_mysqldump_executable_path();
128
 
129
  }
 
130
  }
131
  Requirements::register( 'HM\BackUpWordPress\Requirement_Mysqldump_Command_Path', 'Server' );
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  /**
134
  * Class Requirement_PHP_Version
135
  */
146
  public static function test() {
147
  return PHP_VERSION;
148
  }
 
149
  }
150
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Version', 'PHP' );
151
 
173
  return $cron;
174
 
175
  }
 
176
  }
177
  Requirements::register( 'HM\BackUpWordPress\Requirement_Cron_Array', 'Site' );
178
 
205
  return 'en_US';
206
 
207
  }
 
208
  }
209
  Requirements::register( 'HM\BackUpWordPress\Requirement_Language', 'Site' );
210
 
224
  public static function test() {
225
  return Backup_Utilities::is_safe_mode_on();
226
  }
 
227
  }
228
  Requirements::register( 'HM\BackUpWordPress\Requirement_Safe_Mode', 'PHP' );
229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  /**
231
  * Class Requirement_Memory_Limit
232
  */
243
  public static function test() {
244
  return @ini_get( 'memory_limit' );
245
  }
 
246
  }
247
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Memory_Limit', 'PHP' );
248
 
262
  public static function test() {
263
  return Path::get_path();
264
  }
 
265
  }
266
  Requirements::register( 'HM\BackUpWordPress\Requirement_Backup_Path', 'Site' );
267
 
281
  public static function test() {
282
  return substr( sprintf( '%o', fileperms( Path::get_path() ) ), - 4 );
283
  }
 
284
  }
285
  Requirements::register( 'HM\BackUpWordPress\Requirement_Backup_Path_Permissions', 'Site' );
286
 
300
  public static function test() {
301
  return WP_CONTENT_DIR;
302
  }
 
303
  }
304
  Requirements::register( 'HM\BackUpWordPress\Requirement_WP_CONTENT_DIR', 'Site' );
305
 
319
  public static function test() {
320
  return substr( sprintf( '%o', fileperms( WP_CONTENT_DIR ) ), - 4 );
321
  }
 
322
  }
323
  Requirements::register( 'HM\BackUpWordPress\Requirement_WP_CONTENT_DIR_Permissions', 'Site' );
324
 
338
  public static function test() {
339
  return ABSPATH;
340
  }
 
341
  }
342
  Requirements::register( 'HM\BackUpWordPress\Requirement_ABSPATH', 'Site' );
343
 
357
  public static function test() {
358
  return Path::get_root();
359
  }
 
360
  }
361
  Requirements::register( 'HM\BackUpWordPress\Requirement_Backup_Root_Path', 'Site' );
362
 
386
  if ( $site_size->is_site_size_cached() ) {
387
  $backup_sizes[ $schedule->get_type() ] = $site_size->get_formatted_site_size();
388
  }
 
389
  }
390
 
391
  return $backup_sizes;
392
 
393
  }
 
394
  }
395
  Requirements::register( 'HM\BackUpWordPress\Requirement_Calculated_Size', 'Site' );
396
 
410
  public static function test() {
411
  return (bool) get_option( 'hmbkp_wp_cron_test_failed' );
412
  }
 
413
  }
414
  Requirements::register( 'HM\BackUpWordPress\Requirement_WP_Cron_Test', 'Site' );
415
 
429
  public static function test() {
430
  return php_sapi_name();
431
  }
 
432
  }
433
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_API', 'PHP' );
434
 
447
  */
448
  public static function test() {
449
 
450
+ if ( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
451
  return $_SERVER['SERVER_SOFTWARE'];
452
+ }
453
 
454
  return false;
455
 
456
  }
 
457
  }
458
  Requirements::register( 'HM\BackUpWordPress\Requirement_Server_Software', 'Server' );
459
 
473
  public static function test() {
474
  return PHP_OS;
475
  }
 
476
  }
477
  Requirements::register( 'HM\BackUpWordPress\Requirement_Server_OS', 'Server' );
478
 
492
  public static function test() {
493
  return @ini_get( 'disable_functions' );
494
  }
 
495
  }
496
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Disable_Functions', 'PHP' );
497
 
511
  public static function test() {
512
  return @ini_get( 'open_basedir' );
513
  }
 
514
  }
515
  Requirements::register( 'HM\BackUpWordPress\Requirement_PHP_Open_Basedir', 'PHP' );
516
 
532
  public static function test() {
533
  return defined( 'HMBKP_PATH' ) ? HMBKP_PATH : '';
534
  }
 
535
  }
536
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_PATH', 'constants' );
537
 
551
  public static function test() {
552
  return defined( 'HMBKP_ROOT' ) ? HMBKP_ROOT : '';
553
  }
 
554
  }
555
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_ROOT', 'constants' );
556
 
570
  public static function test() {
571
  return defined( 'HMBKP_MYSQLDUMP_PATH' ) ? HMBKP_MYSQLDUMP_PATH : '';
572
  }
 
573
  }
574
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_MYSQLDUMP_PATH', 'constants' );
575
 
589
  public static function test() {
590
  return defined( 'HMBKP_ZIP_PATH' ) ? HMBKP_ZIP_PATH : '';
591
  }
 
592
  }
593
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_ZIP_PATH', 'constants' );
594
 
608
  public static function test() {
609
  return defined( 'HMBKP_CAPABILITY' ) ? HMBKP_CAPABILITY : '';
610
  }
 
611
  }
612
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_CAPABILITY', 'constants' );
613
 
627
  public static function test() {
628
  return defined( 'HMBKP_EMAIL' ) ? HMBKP_EMAIL : '';
629
  }
 
630
  }
631
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_EMAIL', 'constants' );
632
 
646
  public static function test() {
647
  return defined( 'HMBKP_ATTACHMENT_MAX_FILESIZE' ) ? HMBKP_ATTACHMENT_MAX_FILESIZE : '';
648
  }
 
649
  }
650
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_ATTACHMENT_MAX_FILESIZE', 'constants' );
651
 
665
  public static function test() {
666
  return defined( 'HMBKP_EXCLUDE' ) ? HMBKP_EXCLUDE : '';
667
  }
 
668
  }
669
  Requirements::register( 'HM\BackUpWordPress\Requirement_Define_HMBKP_EXCLUDE', 'constants' );
670
 
672
 
673
  var $name = 'Active Plugins';
674
 
675
+ public static function test() {
676
  return get_option( 'active_plugins' );
677
  }
 
678
  }
679
  Requirements::register( 'HM\BackUpWordPress\Requirement_Active_Plugins', 'Site' );
680
 
682
 
683
  var $name = 'Home URL';
684
 
685
+ public static function test() {
686
  return home_url();
687
  }
 
688
  }
689
  Requirements::register( 'HM\BackUpWordPress\Requirement_Home_Url', 'Site' );
690
 
695
  public static function test() {
696
  return site_url();
697
  }
 
698
  }
699
  Requirements::register( 'HM\BackUpWordPress\Requirement_Site_Url', 'Site' );
700
 
711
 
712
  var $name = 'Max execution time';
713
 
714
+ public static function test() {
715
  return @ini_get( 'max_execution_time' );
716
  }
717
  }
731
 
732
  }
733
  }
734
+
735
  Requirements::register( 'HM\BackUpWordPress\Requirement_PDO', 'PHP' );
736
+
737
+ /**
738
+ * Class Requirement_Proc_Open
739
+ */
740
+ class Requirement_Proc_Open extends Requirement {
741
+
742
+ /**
743
+ * @var string
744
+ */
745
+ var $name = 'proc_open';
746
+
747
+ /**
748
+ * @return bool
749
+ */
750
+ public static function test() {
751
+ return function_exists( 'proc_open' );
752
+ }
753
+ }
754
+ Requirements::register( 'HM\BackUpWordPress\Requirement_Proc_Open', 'PHP' );
classes/class-site-size.php CHANGED
@@ -97,8 +97,8 @@ class Site_Size {
97
  *
98
  * @return bool
99
  */
100
- public static function is_site_size_cached() {
101
- return false !== get_transient( 'hmbkp_directory_filesizes' );
102
  }
103
 
104
  /**
@@ -120,7 +120,7 @@ class Site_Size {
120
  @set_time_limit( 0 );
121
 
122
  // Use the cached array directory sizes if available
123
- $directory_sizes = get_transient( 'hmbkp_directory_filesizes' );
124
 
125
  // If we do have it in cache then let's use it and also clear the lock
126
  if ( is_array( $directory_sizes ) ) {
@@ -143,10 +143,9 @@ class Site_Size {
143
  } else {
144
  $directory_sizes[ wp_normalize_path( $file->getRealpath() ) ] = 0;
145
  }
146
-
147
  }
148
 
149
- set_transient( 'hmbkp_directory_filesizes', $directory_sizes, DAY_IN_SECONDS );
150
 
151
  // Remove the lock
152
  delete_transient( 'hmbkp_directory_filesizes_running' );
@@ -187,8 +186,7 @@ class Site_Size {
187
  public function directory_filesize( \SplFileInfo $file ) {
188
 
189
  // If we haven't calculated the site size yet then kick it off in a thread
190
- $directory_sizes = get_transient( 'hmbkp_directory_filesizes' );
191
-
192
 
193
  if ( ! is_array( $directory_sizes ) ) {
194
  $this->rebuild_directory_filesizes();
@@ -228,4 +226,20 @@ class Site_Size {
228
 
229
  }
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  }
97
  *
98
  * @return bool
99
  */
100
+ public function is_site_size_cached() {
101
+ return (bool) $this->get_cached_filesizes();
102
  }
103
 
104
  /**
120
  @set_time_limit( 0 );
121
 
122
  // Use the cached array directory sizes if available
123
+ $directory_sizes = $this->get_cached_filesizes();
124
 
125
  // If we do have it in cache then let's use it and also clear the lock
126
  if ( is_array( $directory_sizes ) ) {
143
  } else {
144
  $directory_sizes[ wp_normalize_path( $file->getRealpath() ) ] = 0;
145
  }
 
146
  }
147
 
148
+ file_put_contents( PATH::get_path() . '/.files', gzcompress( json_encode( $directory_sizes ) ) );
149
 
150
  // Remove the lock
151
  delete_transient( 'hmbkp_directory_filesizes_running' );
186
  public function directory_filesize( \SplFileInfo $file ) {
187
 
188
  // If we haven't calculated the site size yet then kick it off in a thread
189
+ $directory_sizes = $this->get_cached_filesizes();
 
190
 
191
  if ( ! is_array( $directory_sizes ) ) {
192
  $this->rebuild_directory_filesizes();
226
 
227
  }
228
 
229
+ public function get_cached_filesizes( $max_age = WEEK_IN_SECONDS ) {
230
+
231
+ $cache = PATH::get_path() . '/.files';
232
+ $files = false;
233
+
234
+ if ( file_exists( $cache ) ) {
235
+
236
+ // If the file is old then regenerate it
237
+ if ( ( time() - filemtime( $cache ) ) <= $max_age ) {
238
+ $files = json_decode( gzuncompress( file_get_contents( $cache ) ), 'ARRAY_A' );
239
+ }
240
+ }
241
+
242
+ return $files;
243
+
244
+ }
245
  }
composer.json CHANGED
@@ -19,7 +19,8 @@
19
  "issues": "https://github.com/humanmade/backupwordpress/issues"
20
  },
21
  "require": {
22
- "symfony/finder": "~2.6",
23
- "ifsnop/mysqldump-php":"2.*"
 
24
  }
25
  }
19
  "issues": "https://github.com/humanmade/backupwordpress/issues"
20
  },
21
  "require": {
22
+ "symfony/finder": "~2.8",
23
+ "symfony/process": "~2.8",
24
+ "ifsnop/mysqldump-php":"~2.1"
25
  }
26
  }
composer.lock CHANGED
@@ -4,8 +4,8 @@
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5
  "This file is @generated automatically"
6
  ],
7
- "hash": "a5d481f4e8a2c50cc0c488d199f4c83e",
8
- "content-hash": "77f3dd81e4007d746a29f10fd5dce8af",
9
  "packages": [
10
  {
11
  "name": "ifsnop/mysqldump-php",
@@ -61,16 +61,16 @@
61
  },
62
  {
63
  "name": "symfony/finder",
64
- "version": "v2.8.2",
65
  "source": {
66
  "type": "git",
67
  "url": "https://github.com/symfony/finder.git",
68
- "reference": "c90fabdd97e431ee19b6383999cf35334dff27da"
69
  },
70
  "dist": {
71
  "type": "zip",
72
- "url": "https://api.github.com/repos/symfony/finder/zipball/c90fabdd97e431ee19b6383999cf35334dff27da",
73
- "reference": "c90fabdd97e431ee19b6383999cf35334dff27da",
74
  "shasum": ""
75
  },
76
  "require": {
@@ -106,7 +106,56 @@
106
  ],
107
  "description": "Symfony Finder Component",
108
  "homepage": "https://symfony.com",
109
- "time": "2016-01-14 08:26:52"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  }
111
  ],
112
  "packages-dev": [],
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5
  "This file is @generated automatically"
6
  ],
7
+ "hash": "5bc2486184bdd88cfe98a9f29529263c",
8
+ "content-hash": "178e95a25ce4467f191024f0a677b2df",
9
  "packages": [
10
  {
11
  "name": "ifsnop/mysqldump-php",
61
  },
62
  {
63
  "name": "symfony/finder",
64
+ "version": "v2.8.3",
65
  "source": {
66
  "type": "git",
67
  "url": "https://github.com/symfony/finder.git",
68
+ "reference": "877bb4b16ea573cc8c024e9590888fcf7eb7e0f7"
69
  },
70
  "dist": {
71
  "type": "zip",
72
+ "url": "https://api.github.com/repos/symfony/finder/zipball/877bb4b16ea573cc8c024e9590888fcf7eb7e0f7",
73
+ "reference": "877bb4b16ea573cc8c024e9590888fcf7eb7e0f7",
74
  "shasum": ""
75
  },
76
  "require": {
106
  ],
107
  "description": "Symfony Finder Component",
108
  "homepage": "https://symfony.com",
109
+ "time": "2016-02-22 16:12:45"
110
+ },
111
+ {
112
+ "name": "symfony/process",
113
+ "version": "v2.8.3",
114
+ "source": {
115
+ "type": "git",
116
+ "url": "https://github.com/symfony/process.git",
117
+ "reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe"
118
+ },
119
+ "dist": {
120
+ "type": "zip",
121
+ "url": "https://api.github.com/repos/symfony/process/zipball/7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe",
122
+ "reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe",
123
+ "shasum": ""
124
+ },
125
+ "require": {
126
+ "php": ">=5.3.9"
127
+ },
128
+ "type": "library",
129
+ "extra": {
130
+ "branch-alias": {
131
+ "dev-master": "2.8-dev"
132
+ }
133
+ },
134
+ "autoload": {
135
+ "psr-4": {
136
+ "Symfony\\Component\\Process\\": ""
137
+ },
138
+ "exclude-from-classmap": [
139
+ "/Tests/"
140
+ ]
141
+ },
142
+ "notification-url": "https://packagist.org/downloads/",
143
+ "license": [
144
+ "MIT"
145
+ ],
146
+ "authors": [
147
+ {
148
+ "name": "Fabien Potencier",
149
+ "email": "fabien@symfony.com"
150
+ },
151
+ {
152
+ "name": "Symfony Community",
153
+ "homepage": "https://symfony.com/contributors"
154
+ }
155
+ ],
156
+ "description": "Symfony Process Component",
157
+ "homepage": "https://symfony.com",
158
+ "time": "2016-02-02 13:33:15"
159
  }
160
  ],
161
  "packages-dev": [],
functions/core.php CHANGED
@@ -261,7 +261,7 @@ function update() {
261
  }
262
  }
263
 
264
- // Update from PRIOR_VERSION
265
  if ( get_option( 'hmbkp_plugin_version' ) && version_compare( '3.3.0', get_option( 'hmbkp_plugin_version' ), '>' ) ) {
266
 
267
  $schedules = Schedules::get_instance();
@@ -281,11 +281,16 @@ function update() {
281
 
282
  }
283
 
 
 
 
 
 
284
  // Every update
285
  if ( get_option( 'hmbkp_plugin_version' ) && version_compare( Plugin::PLUGIN_VERSION, get_option( 'hmbkp_plugin_version' ), '>' ) ) {
286
 
287
  require_once( HMBKP_PLUGIN_PATH . 'classes/class-setup.php' );
288
-
289
  \HMBKP_Setup::deactivate();
290
 
291
  Path::get_instance()->protect_path( 'reset' );
261
  }
262
  }
263
 
264
+ // Update from 3.3.0
265
  if ( get_option( 'hmbkp_plugin_version' ) && version_compare( '3.3.0', get_option( 'hmbkp_plugin_version' ), '>' ) ) {
266
 
267
  $schedules = Schedules::get_instance();
281
 
282
  }
283
 
284
+ // Update from 3.3.4
285
+ if ( get_option( 'hmbkp_plugin_version' ) && version_compare( '3.4.0', get_option( 'hmbkp_plugin_version' ), '>' ) ) {
286
+ delete_transient( 'hmbkp_directory_filesizes' );
287
+ }
288
+
289
  // Every update
290
  if ( get_option( 'hmbkp_plugin_version' ) && version_compare( Plugin::PLUGIN_VERSION, get_option( 'hmbkp_plugin_version' ), '>' ) ) {
291
 
292
  require_once( HMBKP_PLUGIN_PATH . 'classes/class-setup.php' );
293
+
294
  \HMBKP_Setup::deactivate();
295
 
296
  Path::get_instance()->protect_path( 'reset' );
languages/backupwordpress.pot CHANGED
@@ -2,16 +2,16 @@
2
  # This file is distributed under the GPL-2+.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: BackUpWordPress 3.4.5\n"
6
  "Report-Msgid-Bugs-To: backupwordpress@hmn.md\n"
7
- "POT-Creation-Date: 2016-02-23 17:28:10+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
  "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: Human Made Limited\n"
13
  "Language-Team: Human Made Limited\n"
14
- "X-Generator: grunt-wp-i18n 0.5.3\n"
15
 
16
  #: admin/actions.php:180
17
  msgid "The schedule ID was not provided. Aborting."
@@ -80,11 +80,11 @@ msgid ""
80
  "for manual backups. See the %3$s for more details."
81
  msgstr ""
82
 
83
- #: admin/backups-table.php:14 admin/schedule-form-excludes.php:109
84
  msgid "Size"
85
  msgstr ""
86
 
87
- #: admin/backups-table.php:15 admin/schedule-form-excludes.php:111
88
  msgid "Type"
89
  msgstr ""
90
 
@@ -441,59 +441,59 @@ msgid ""
441
  "backup."
442
  msgstr ""
443
 
444
- #: admin/schedule-form-excludes.php:108
445
  msgid "Name"
446
  msgstr ""
447
 
448
- #: admin/schedule-form-excludes.php:110
449
  msgid "Permissions"
450
  msgstr ""
451
 
452
- #: admin/schedule-form-excludes.php:112
453
  msgid "Status"
454
  msgstr ""
455
 
456
- #: admin/schedule-form-excludes.php:172 admin/schedule-form-excludes.php:290
457
  msgid "Refresh"
458
  msgstr ""
459
 
460
- #: admin/schedule-form-excludes.php:189 admin/schedule-form-excludes.php:314
461
  msgid "Symlink"
462
  msgstr ""
463
 
464
- #: admin/schedule-form-excludes.php:193 admin/schedule-form-excludes.php:318
465
  msgid "Folder"
466
  msgstr ""
467
 
468
- #: admin/schedule-form-excludes.php:288
469
  msgid "Recalculate the size of this directory"
470
  msgstr ""
471
 
472
- #: admin/schedule-form-excludes.php:322
473
  msgid "File"
474
  msgstr ""
475
 
476
- #: admin/schedule-form-excludes.php:333
477
  msgid "Unreadable files won't be backed up."
478
  msgstr ""
479
 
480
- #: admin/schedule-form-excludes.php:333
481
  msgid "Unreadable"
482
  msgstr ""
483
 
484
- #: admin/schedule-form-excludes.php:337
485
  msgid "Excluded"
486
  msgstr ""
487
 
488
- #: admin/schedule-form-excludes.php:353
489
  msgid "Exclude &rarr;"
490
  msgstr ""
491
 
492
- #: admin/schedule-form-excludes.php:366
493
  msgid "This folder is empty"
494
  msgstr ""
495
 
496
- #: admin/schedule-form-excludes.php:378 admin/schedule-form.php:204
497
  #: admin/schedule-settings.php:90
498
  msgid "Done"
499
  msgstr ""
@@ -893,41 +893,41 @@ msgstr ""
893
  msgid "Error: %s"
894
  msgstr ""
895
 
896
- #: functions/core.php:338
897
  msgid "BackUpWordPress has set up your default schedules."
898
  msgstr ""
899
 
900
- #: functions/core.php:338
901
  msgid ""
902
  "By default BackUpWordPress performs a daily backup of your database and a "
903
  "weekly backup of your database &amp; files. You can modify these schedules."
904
  msgstr ""
905
 
906
- #: functions/core.php:354
907
  msgid "Once Hourly"
908
  msgstr ""
909
 
910
- #: functions/core.php:355
911
  msgid "Twice Daily"
912
  msgstr ""
913
 
914
- #: functions/core.php:356
915
  msgid "Once Daily"
916
  msgstr ""
917
 
918
- #: functions/core.php:357
919
  msgid "Once Weekly"
920
  msgstr ""
921
 
922
- #: functions/core.php:358
923
  msgid "Once Every Two Weeks"
924
  msgstr ""
925
 
926
- #: functions/core.php:359
927
  msgid "Once Monthly"
928
  msgstr ""
929
 
930
- #: functions/core.php:378
931
  msgid "You can only delete directories inside your WordPress installation"
932
  msgstr ""
933
 
2
  # This file is distributed under the GPL-2+.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: BackUpWordPress 3.4.6\n"
6
  "Report-Msgid-Bugs-To: backupwordpress@hmn.md\n"
7
+ "POT-Creation-Date: 2016-03-03 11:11:49+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
  "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: Human Made Limited\n"
13
  "Language-Team: Human Made Limited\n"
14
+ "X-Generator: grunt-wp-i18n 0.5.4\n"
15
 
16
  #: admin/actions.php:180
17
  msgid "The schedule ID was not provided. Aborting."
80
  "for manual backups. See the %3$s for more details."
81
  msgstr ""
82
 
83
+ #: admin/backups-table.php:14 admin/schedule-form-excludes.php:108
84
  msgid "Size"
85
  msgstr ""
86
 
87
+ #: admin/backups-table.php:15 admin/schedule-form-excludes.php:110
88
  msgid "Type"
89
  msgstr ""
90
 
441
  "backup."
442
  msgstr ""
443
 
444
+ #: admin/schedule-form-excludes.php:107
445
  msgid "Name"
446
  msgstr ""
447
 
448
+ #: admin/schedule-form-excludes.php:109
449
  msgid "Permissions"
450
  msgstr ""
451
 
452
+ #: admin/schedule-form-excludes.php:111
453
  msgid "Status"
454
  msgstr ""
455
 
456
+ #: admin/schedule-form-excludes.php:171 admin/schedule-form-excludes.php:279
457
  msgid "Refresh"
458
  msgstr ""
459
 
460
+ #: admin/schedule-form-excludes.php:187 admin/schedule-form-excludes.php:303
461
  msgid "Symlink"
462
  msgstr ""
463
 
464
+ #: admin/schedule-form-excludes.php:189 admin/schedule-form-excludes.php:306
465
  msgid "Folder"
466
  msgstr ""
467
 
468
+ #: admin/schedule-form-excludes.php:279
469
  msgid "Recalculate the size of this directory"
470
  msgstr ""
471
 
472
+ #: admin/schedule-form-excludes.php:308
473
  msgid "File"
474
  msgstr ""
475
 
476
+ #: admin/schedule-form-excludes.php:317
477
  msgid "Unreadable files won't be backed up."
478
  msgstr ""
479
 
480
+ #: admin/schedule-form-excludes.php:317
481
  msgid "Unreadable"
482
  msgstr ""
483
 
484
+ #: admin/schedule-form-excludes.php:321
485
  msgid "Excluded"
486
  msgstr ""
487
 
488
+ #: admin/schedule-form-excludes.php:337
489
  msgid "Exclude &rarr;"
490
  msgstr ""
491
 
492
+ #: admin/schedule-form-excludes.php:350
493
  msgid "This folder is empty"
494
  msgstr ""
495
 
496
+ #: admin/schedule-form-excludes.php:361 admin/schedule-form.php:204
497
  #: admin/schedule-settings.php:90
498
  msgid "Done"
499
  msgstr ""
893
  msgid "Error: %s"
894
  msgstr ""
895
 
896
+ #: functions/core.php:343
897
  msgid "BackUpWordPress has set up your default schedules."
898
  msgstr ""
899
 
900
+ #: functions/core.php:343
901
  msgid ""
902
  "By default BackUpWordPress performs a daily backup of your database and a "
903
  "weekly backup of your database &amp; files. You can modify these schedules."
904
  msgstr ""
905
 
906
+ #: functions/core.php:359
907
  msgid "Once Hourly"
908
  msgstr ""
909
 
910
+ #: functions/core.php:360
911
  msgid "Twice Daily"
912
  msgstr ""
913
 
914
+ #: functions/core.php:361
915
  msgid "Once Daily"
916
  msgstr ""
917
 
918
+ #: functions/core.php:362
919
  msgid "Once Weekly"
920
  msgstr ""
921
 
922
+ #: functions/core.php:363
923
  msgid "Once Every Two Weeks"
924
  msgstr ""
925
 
926
+ #: functions/core.php:364
927
  msgid "Once Monthly"
928
  msgstr ""
929
 
930
+ #: functions/core.php:383
931
  msgid "You can only delete directories inside your WordPress installation"
932
  msgstr ""
933
 
uninstall.php CHANGED
@@ -10,6 +10,13 @@ if ( ! current_user_can( 'activate_plugins' ) ) {
10
 
11
  global $wpdb;
12
 
 
 
 
 
 
 
 
13
  // Get all schedule options with a SELECT query and delete them.
14
  $schedules = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", 'hmbkp_schedule_%' ) );
15
 
10
 
11
  global $wpdb;
12
 
13
+ require_once dirname( __FILE__ ) . '/classes/class-path.php';
14
+
15
+ // Delete the file manifest if it exists
16
+ if ( file_exists( HM\BackUpWordPress\PATH::get_path() . '/.files' ) ) {
17
+ unlink( HM\BackUpWordPress\PATH::get_path() . '/.files' );
18
+ }
19
+
20
  // Get all schedule options with a SELECT query and delete them.
21
  $schedules = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", 'hmbkp_schedule_%' ) );
22
 
vendor/composer/ClassLoader.php CHANGED
@@ -13,9 +13,7 @@
13
  namespace Composer\Autoload;
14
 
15
  /**
16
- * ClassLoader implements a PSR-0 class loader
17
- *
18
- * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
19
  *
20
  * $loader = new \Composer\Autoload\ClassLoader();
21
  *
@@ -39,6 +37,8 @@ namespace Composer\Autoload;
39
  *
40
  * @author Fabien Potencier <fabien@symfony.com>
41
  * @author Jordi Boggiano <j.boggiano@seld.be>
 
 
42
  */
43
  class ClassLoader
44
  {
@@ -147,7 +147,7 @@ class ClassLoader
147
  * appending or prepending to the ones previously set for this namespace.
148
  *
149
  * @param string $prefix The prefix/namespace, with trailing '\\'
150
- * @param array|string $paths The PSR-0 base directories
151
  * @param bool $prepend Whether to prepend the directories
152
  *
153
  * @throws \InvalidArgumentException
13
  namespace Composer\Autoload;
14
 
15
  /**
16
+ * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
 
 
17
  *
18
  * $loader = new \Composer\Autoload\ClassLoader();
19
  *
37
  *
38
  * @author Fabien Potencier <fabien@symfony.com>
39
  * @author Jordi Boggiano <j.boggiano@seld.be>
40
+ * @see http://www.php-fig.org/psr/psr-0/
41
+ * @see http://www.php-fig.org/psr/psr-4/
42
  */
43
  class ClassLoader
44
  {
147
  * appending or prepending to the ones previously set for this namespace.
148
  *
149
  * @param string $prefix The prefix/namespace, with trailing '\\'
150
+ * @param array|string $paths The PSR-4 base directories
151
  * @param bool $prepend Whether to prepend the directories
152
  *
153
  * @throws \InvalidArgumentException
vendor/composer/autoload_psr4.php CHANGED
@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
 
9
  'Symfony\\Component\\Finder\\' => array($vendorDir . '/symfony/finder'),
10
  'Ifsnop\\' => array($vendorDir . '/ifsnop/mysqldump-php/src/Ifsnop'),
11
  );
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
9
+ 'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
10
  'Symfony\\Component\\Finder\\' => array($vendorDir . '/symfony/finder'),
11
  'Ifsnop\\' => array($vendorDir . '/ifsnop/mysqldump-php/src/Ifsnop'),
12
  );
vendor/composer/autoload_real.php CHANGED
@@ -43,8 +43,3 @@ class ComposerAutoloaderInitffc53c57bb8d99be0f3745ccee4cdfec
43
  return $loader;
44
  }
45
  }
46
-
47
- function composerRequireffc53c57bb8d99be0f3745ccee4cdfec($file)
48
- {
49
- require $file;
50
- }
43
  return $loader;
44
  }
45
  }
 
 
 
 
 
vendor/composer/installed.json CHANGED
@@ -1,23 +1,77 @@
1
  [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  {
3
  "name": "symfony/finder",
4
- "version": "v2.8.2",
5
- "version_normalized": "2.8.2.0",
6
  "source": {
7
  "type": "git",
8
  "url": "https://github.com/symfony/finder.git",
9
- "reference": "c90fabdd97e431ee19b6383999cf35334dff27da"
10
  },
11
  "dist": {
12
  "type": "zip",
13
- "url": "https://api.github.com/repos/symfony/finder/zipball/c90fabdd97e431ee19b6383999cf35334dff27da",
14
- "reference": "c90fabdd97e431ee19b6383999cf35334dff27da",
15
  "shasum": ""
16
  },
17
  "require": {
18
  "php": ">=5.3.9"
19
  },
20
- "time": "2016-01-14 08:26:52",
21
  "type": "library",
22
  "extra": {
23
  "branch-alias": {
@@ -51,34 +105,38 @@
51
  "homepage": "https://symfony.com"
52
  },
53
  {
54
- "name": "ifsnop/mysqldump-php",
55
- "version": "v2.1",
56
- "version_normalized": "2.1.0.0",
57
  "source": {
58
  "type": "git",
59
- "url": "https://github.com/ifsnop/mysqldump-php.git",
60
- "reference": "701024dd160f15796bed8130c3bdeb26c634785a"
61
  },
62
  "dist": {
63
  "type": "zip",
64
- "url": "https://api.github.com/repos/ifsnop/mysqldump-php/zipball/701024dd160f15796bed8130c3bdeb26c634785a",
65
- "reference": "701024dd160f15796bed8130c3bdeb26c634785a",
66
  "shasum": ""
67
  },
68
  "require": {
69
- "php": ">=5.3.0"
70
- },
71
- "require-dev": {
72
- "phpunit/phpunit": "3.7.*",
73
- "squizlabs/php_codesniffer": "1.*"
74
  },
75
- "time": "2015-10-19 15:58:11",
76
  "type": "library",
 
 
 
 
 
77
  "installation-source": "dist",
78
  "autoload": {
79
  "psr-4": {
80
- "Ifsnop\\": "src/Ifsnop/"
81
- }
 
 
 
82
  },
83
  "notification-url": "https://packagist.org/downloads/",
84
  "license": [
@@ -86,22 +144,15 @@
86
  ],
87
  "authors": [
88
  {
89
- "name": "Diego Torres",
90
- "homepage": "https://github.com/ifsnop",
91
- "role": "Developer"
 
 
 
92
  }
93
  ],
94
- "description": "This is a php version of linux's mysqldump in terminal \"$ mysqldump -u username -p...\"",
95
- "homepage": "https://github.com/ifsnop/mysqldump-php",
96
- "keywords": [
97
- "backup",
98
- "database",
99
- "dump",
100
- "export",
101
- "mysql",
102
- "mysqldump",
103
- "pdo",
104
- "sqlite"
105
- ]
106
  }
107
  ]
1
  [
2
+ {
3
+ "name": "ifsnop/mysqldump-php",
4
+ "version": "v2.1",
5
+ "version_normalized": "2.1.0.0",
6
+ "source": {
7
+ "type": "git",
8
+ "url": "https://github.com/ifsnop/mysqldump-php.git",
9
+ "reference": "701024dd160f15796bed8130c3bdeb26c634785a"
10
+ },
11
+ "dist": {
12
+ "type": "zip",
13
+ "url": "https://api.github.com/repos/ifsnop/mysqldump-php/zipball/701024dd160f15796bed8130c3bdeb26c634785a",
14
+ "reference": "701024dd160f15796bed8130c3bdeb26c634785a",
15
+ "shasum": ""
16
+ },
17
+ "require": {
18
+ "php": ">=5.3.0"
19
+ },
20
+ "require-dev": {
21
+ "phpunit/phpunit": "3.7.*",
22
+ "squizlabs/php_codesniffer": "1.*"
23
+ },
24
+ "time": "2015-10-19 15:58:11",
25
+ "type": "library",
26
+ "installation-source": "dist",
27
+ "autoload": {
28
+ "psr-4": {
29
+ "Ifsnop\\": "src/Ifsnop/"
30
+ }
31
+ },
32
+ "notification-url": "https://packagist.org/downloads/",
33
+ "license": [
34
+ "MIT"
35
+ ],
36
+ "authors": [
37
+ {
38
+ "name": "Diego Torres",
39
+ "homepage": "https://github.com/ifsnop",
40
+ "role": "Developer"
41
+ }
42
+ ],
43
+ "description": "This is a php version of linux's mysqldump in terminal \"$ mysqldump -u username -p...\"",
44
+ "homepage": "https://github.com/ifsnop/mysqldump-php",
45
+ "keywords": [
46
+ "backup",
47
+ "database",
48
+ "dump",
49
+ "export",
50
+ "mysql",
51
+ "mysqldump",
52
+ "pdo",
53
+ "sqlite"
54
+ ]
55
+ },
56
  {
57
  "name": "symfony/finder",
58
+ "version": "v2.8.3",
59
+ "version_normalized": "2.8.3.0",
60
  "source": {
61
  "type": "git",
62
  "url": "https://github.com/symfony/finder.git",
63
+ "reference": "877bb4b16ea573cc8c024e9590888fcf7eb7e0f7"
64
  },
65
  "dist": {
66
  "type": "zip",
67
+ "url": "https://api.github.com/repos/symfony/finder/zipball/877bb4b16ea573cc8c024e9590888fcf7eb7e0f7",
68
+ "reference": "877bb4b16ea573cc8c024e9590888fcf7eb7e0f7",
69
  "shasum": ""
70
  },
71
  "require": {
72
  "php": ">=5.3.9"
73
  },
74
+ "time": "2016-02-22 16:12:45",
75
  "type": "library",
76
  "extra": {
77
  "branch-alias": {
105
  "homepage": "https://symfony.com"
106
  },
107
  {
108
+ "name": "symfony/process",
109
+ "version": "v2.8.3",
110
+ "version_normalized": "2.8.3.0",
111
  "source": {
112
  "type": "git",
113
+ "url": "https://github.com/symfony/process.git",
114
+ "reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe"
115
  },
116
  "dist": {
117
  "type": "zip",
118
+ "url": "https://api.github.com/repos/symfony/process/zipball/7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe",
119
+ "reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe",
120
  "shasum": ""
121
  },
122
  "require": {
123
+ "php": ">=5.3.9"
 
 
 
 
124
  },
125
+ "time": "2016-02-02 13:33:15",
126
  "type": "library",
127
+ "extra": {
128
+ "branch-alias": {
129
+ "dev-master": "2.8-dev"
130
+ }
131
+ },
132
  "installation-source": "dist",
133
  "autoload": {
134
  "psr-4": {
135
+ "Symfony\\Component\\Process\\": ""
136
+ },
137
+ "exclude-from-classmap": [
138
+ "/Tests/"
139
+ ]
140
  },
141
  "notification-url": "https://packagist.org/downloads/",
142
  "license": [
144
  ],
145
  "authors": [
146
  {
147
+ "name": "Fabien Potencier",
148
+ "email": "fabien@symfony.com"
149
+ },
150
+ {
151
+ "name": "Symfony Community",
152
+ "homepage": "https://symfony.com/contributors"
153
  }
154
  ],
155
+ "description": "Symfony Process Component",
156
+ "homepage": "https://symfony.com"
 
 
 
 
 
 
 
 
 
 
157
  }
158
  ]
vendor/symfony/finder/Adapter/AbstractFindAdapter.php CHANGED
@@ -98,7 +98,7 @@ abstract class AbstractFindAdapter extends AbstractAdapter
98
  $command->setErrorHandler(
99
  $this->ignoreUnreadableDirs
100
  // If directory is unreadable and finder is set to ignore it, `stderr` is ignored.
101
- ? function ($stderr) { return; }
102
  : function ($stderr) { throw new AccessDeniedException($stderr); }
103
  );
104
 
98
  $command->setErrorHandler(
99
  $this->ignoreUnreadableDirs
100
  // If directory is unreadable and finder is set to ignore it, `stderr` is ignored.
101
+ ? function ($stderr) { }
102
  : function ($stderr) { throw new AccessDeniedException($stderr); }
103
  );
104
 
vendor/symfony/finder/Glob.php CHANGED
@@ -66,7 +66,7 @@ class Glob
66
  $firstByte = true;
67
  }
68
 
69
- if ('.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
70
  $regex .= "\\$car";
71
  } elseif ('*' === $car) {
72
  $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
66
  $firstByte = true;
67
  }
68
 
69
+ if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
70
  $regex .= "\\$car";
71
  } elseif ('*' === $car) {
72
  $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
vendor/symfony/finder/Iterator/FilterIterator.php CHANGED
@@ -12,9 +12,10 @@
12
  namespace Symfony\Component\Finder\Iterator;
13
 
14
  /**
15
- * This iterator just overrides the rewind method in order to correct a PHP bug.
 
16
  *
17
- * @see https://bugs.php.net/bug.php?id=49104
18
  *
19
  * @author Alex Bogomazov
20
  */
@@ -28,18 +29,19 @@ abstract class FilterIterator extends \FilterIterator
28
  */
29
  public function rewind()
30
  {
 
 
 
 
 
 
31
  $iterator = $this;
32
  while ($iterator instanceof \OuterIterator) {
33
  $innerIterator = $iterator->getInnerIterator();
34
 
35
- if ($innerIterator instanceof RecursiveDirectoryIterator) {
36
- if ($innerIterator->isRewindable()) {
37
- $innerIterator->next();
38
- $innerIterator->rewind();
39
- }
40
- } elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
41
- $iterator->getInnerIterator()->next();
42
- $iterator->getInnerIterator()->rewind();
43
  }
44
  $iterator = $iterator->getInnerIterator();
45
  }
12
  namespace Symfony\Component\Finder\Iterator;
13
 
14
  /**
15
+ * This iterator just overrides the rewind method in order to correct a PHP bug,
16
+ * which existed before version 5.5.23/5.6.7.
17
  *
18
+ * @see https://bugs.php.net/68557
19
  *
20
  * @author Alex Bogomazov
21
  */
29
  */
30
  public function rewind()
31
  {
32
+ if (PHP_VERSION_ID > 50607 || (PHP_VERSION_ID > 50523 && PHP_VERSION_ID < 50600)) {
33
+ parent::rewind();
34
+
35
+ return;
36
+ }
37
+
38
  $iterator = $this;
39
  while ($iterator instanceof \OuterIterator) {
40
  $innerIterator = $iterator->getInnerIterator();
41
 
42
+ if ($innerIterator instanceof \FilesystemIterator) {
43
+ $innerIterator->next();
44
+ $innerIterator->rewind();
 
 
 
 
 
45
  }
46
  $iterator = $iterator->getInnerIterator();
47
  }
vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php CHANGED
@@ -118,8 +118,10 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
118
  return;
119
  }
120
 
121
- // @see https://bugs.php.net/bug.php?id=49104
122
- parent::next();
 
 
123
 
124
  parent::rewind();
125
  }
118
  return;
119
  }
120
 
121
+ // @see https://bugs.php.net/68557
122
+ if (PHP_VERSION_ID < 50523 || PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50607) {
123
+ parent::next();
124
+ }
125
 
126
  parent::rewind();
127
  }
vendor/symfony/finder/SplFileInfo.php CHANGED
@@ -38,6 +38,8 @@ class SplFileInfo extends \SplFileInfo
38
  /**
39
  * Returns the relative path.
40
  *
 
 
41
  * @return string the relative path
42
  */
43
  public function getRelativePath()
@@ -48,6 +50,8 @@ class SplFileInfo extends \SplFileInfo
48
  /**
49
  * Returns the relative path name.
50
  *
 
 
51
  * @return string the relative path name
52
  */
53
  public function getRelativePathname()
38
  /**
39
  * Returns the relative path.
40
  *
41
+ * This path does not contain the file name.
42
+ *
43
  * @return string the relative path
44
  */
45
  public function getRelativePath()
50
  /**
51
  * Returns the relative path name.
52
  *
53
+ * This path contains the file name.
54
+ *
55
  * @return string the relative path name
56
  */
57
  public function getRelativePathname()
vendor/symfony/process/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CHANGELOG
2
+ =========
3
+
4
+ 2.5.0
5
+ -----
6
+
7
+ * added support for PTY mode
8
+ * added the convenience method "mustRun"
9
+ * deprecation: Process::setStdin() is deprecated in favor of Process::setInput()
10
+ * deprecation: Process::getStdin() is deprecated in favor of Process::getInput()
11
+ * deprecation: Process::setInput() and ProcessBuilder::setInput() do not accept non-scalar types
12
+
13
+ 2.4.0
14
+ -----
15
+
16
+ * added the ability to define an idle timeout
17
+
18
+ 2.3.0
19
+ -----
20
+
21
+ * added ProcessUtils::escapeArgument() to fix the bug in escapeshellarg() function on Windows
22
+ * added Process::signal()
23
+ * added Process::getPid()
24
+ * added support for a TTY mode
25
+
26
+ 2.2.0
27
+ -----
28
+
29
+ * added ProcessBuilder::setArguments() to reset the arguments on a builder
30
+ * added a way to retrieve the standard and error output incrementally
31
+ * added Process:restart()
32
+
33
+ 2.1.0
34
+ -----
35
+
36
+ * added support for non-blocking processes (start(), wait(), isRunning(), stop())
37
+ * enhanced Windows compatibility
38
+ * added Process::getExitCodeText() that returns a string representation for
39
+ the exit code returned by the process
40
+ * added ProcessBuilder
vendor/symfony/process/Exception/ExceptionInterface.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Exception;
13
+
14
+ /**
15
+ * Marker Interface for the Process Component.
16
+ *
17
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
18
+ */
19
+ interface ExceptionInterface
20
+ {
21
+ }
vendor/symfony/process/Exception/InvalidArgumentException.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Exception;
13
+
14
+ /**
15
+ * InvalidArgumentException for the Process Component.
16
+ *
17
+ * @author Romain Neutron <imprec@gmail.com>
18
+ */
19
+ class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
20
+ {
21
+ }
vendor/symfony/process/Exception/LogicException.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Exception;
13
+
14
+ /**
15
+ * LogicException for the Process Component.
16
+ *
17
+ * @author Romain Neutron <imprec@gmail.com>
18
+ */
19
+ class LogicException extends \LogicException implements ExceptionInterface
20
+ {
21
+ }
vendor/symfony/process/Exception/ProcessFailedException.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Exception;
13
+
14
+ use Symfony\Component\Process\Process;
15
+
16
+ /**
17
+ * Exception for failed processes.
18
+ *
19
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
20
+ */
21
+ class ProcessFailedException extends RuntimeException
22
+ {
23
+ private $process;
24
+
25
+ public function __construct(Process $process)
26
+ {
27
+ if ($process->isSuccessful()) {
28
+ throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
29
+ }
30
+
31
+ $error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
32
+ $process->getCommandLine(),
33
+ $process->getExitCode(),
34
+ $process->getExitCodeText(),
35
+ $process->getWorkingDirectory()
36
+ );
37
+
38
+ if (!$process->isOutputDisabled()) {
39
+ $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
40
+ $process->getOutput(),
41
+ $process->getErrorOutput()
42
+ );
43
+ }
44
+
45
+ parent::__construct($error);
46
+
47
+ $this->process = $process;
48
+ }
49
+
50
+ public function getProcess()
51
+ {
52
+ return $this->process;
53
+ }
54
+ }
vendor/symfony/process/Exception/ProcessTimedOutException.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Exception;
13
+
14
+ use Symfony\Component\Process\Process;
15
+
16
+ /**
17
+ * Exception that is thrown when a process times out.
18
+ *
19
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
20
+ */
21
+ class ProcessTimedOutException extends RuntimeException
22
+ {
23
+ const TYPE_GENERAL = 1;
24
+ const TYPE_IDLE = 2;
25
+
26
+ private $process;
27
+ private $timeoutType;
28
+
29
+ public function __construct(Process $process, $timeoutType)
30
+ {
31
+ $this->process = $process;
32
+ $this->timeoutType = $timeoutType;
33
+
34
+ parent::__construct(sprintf(
35
+ 'The process "%s" exceeded the timeout of %s seconds.',
36
+ $process->getCommandLine(),
37
+ $this->getExceededTimeout()
38
+ ));
39
+ }
40
+
41
+ public function getProcess()
42
+ {
43
+ return $this->process;
44
+ }
45
+
46
+ public function isGeneralTimeout()
47
+ {
48
+ return $this->timeoutType === self::TYPE_GENERAL;
49
+ }
50
+
51
+ public function isIdleTimeout()
52
+ {
53
+ return $this->timeoutType === self::TYPE_IDLE;
54
+ }
55
+
56
+ public function getExceededTimeout()
57
+ {
58
+ switch ($this->timeoutType) {
59
+ case self::TYPE_GENERAL:
60
+ return $this->process->getTimeout();
61
+
62
+ case self::TYPE_IDLE:
63
+ return $this->process->getIdleTimeout();
64
+
65
+ default:
66
+ throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
67
+ }
68
+ }
69
+ }
vendor/symfony/process/Exception/RuntimeException.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Exception;
13
+
14
+ /**
15
+ * RuntimeException for the Process Component.
16
+ *
17
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
18
+ */
19
+ class RuntimeException extends \RuntimeException implements ExceptionInterface
20
+ {
21
+ }
vendor/symfony/process/ExecutableFinder.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process;
13
+
14
+ /**
15
+ * Generic executable finder.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
19
+ */
20
+ class ExecutableFinder
21
+ {
22
+ private $suffixes = array('.exe', '.bat', '.cmd', '.com');
23
+
24
+ /**
25
+ * Replaces default suffixes of executable.
26
+ *
27
+ * @param array $suffixes
28
+ */
29
+ public function setSuffixes(array $suffixes)
30
+ {
31
+ $this->suffixes = $suffixes;
32
+ }
33
+
34
+ /**
35
+ * Adds new possible suffix to check for executable.
36
+ *
37
+ * @param string $suffix
38
+ */
39
+ public function addSuffix($suffix)
40
+ {
41
+ $this->suffixes[] = $suffix;
42
+ }
43
+
44
+ /**
45
+ * Finds an executable by name.
46
+ *
47
+ * @param string $name The executable name (without the extension)
48
+ * @param string $default The default to return if no executable is found
49
+ * @param array $extraDirs Additional dirs to check into
50
+ *
51
+ * @return string The executable path or default value
52
+ */
53
+ public function find($name, $default = null, array $extraDirs = array())
54
+ {
55
+ if (ini_get('open_basedir')) {
56
+ $searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
57
+ $dirs = array();
58
+ foreach ($searchPath as $path) {
59
+ // Silencing against https://bugs.php.net/69240
60
+ if (@is_dir($path)) {
61
+ $dirs[] = $path;
62
+ } else {
63
+ if (basename($path) == $name && is_executable($path)) {
64
+ return $path;
65
+ }
66
+ }
67
+ }
68
+ } else {
69
+ $dirs = array_merge(
70
+ explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
71
+ $extraDirs
72
+ );
73
+ }
74
+
75
+ $suffixes = array('');
76
+ if ('\\' === DIRECTORY_SEPARATOR) {
77
+ $pathExt = getenv('PATHEXT');
78
+ $suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
79
+ }
80
+ foreach ($suffixes as $suffix) {
81
+ foreach ($dirs as $dir) {
82
+ if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
83
+ return $file;
84
+ }
85
+ }
86
+ }
87
+
88
+ return $default;
89
+ }
90
+ }
vendor/symfony/process/LICENSE ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2004-2016 Fabien Potencier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is furnished
8
+ to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
vendor/symfony/process/PhpExecutableFinder.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process;
13
+
14
+ /**
15
+ * An executable finder specifically designed for the PHP executable.
16
+ *
17
+ * @author Fabien Potencier <fabien@symfony.com>
18
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
19
+ */
20
+ class PhpExecutableFinder
21
+ {
22
+ private $executableFinder;
23
+
24
+ public function __construct()
25
+ {
26
+ $this->executableFinder = new ExecutableFinder();
27
+ }
28
+
29
+ /**
30
+ * Finds The PHP executable.
31
+ *
32
+ * @param bool $includeArgs Whether or not include command arguments
33
+ *
34
+ * @return string|false The PHP executable path or false if it cannot be found
35
+ */
36
+ public function find($includeArgs = true)
37
+ {
38
+ $args = $this->findArguments();
39
+ $args = $includeArgs && $args ? ' '.implode(' ', $args) : '';
40
+
41
+ // HHVM support
42
+ if (defined('HHVM_VERSION')) {
43
+ return (getenv('PHP_BINARY') ?: PHP_BINARY).$args;
44
+ }
45
+
46
+ // PHP_BINARY return the current sapi executable
47
+ if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server', 'phpdbg')) && is_file(PHP_BINARY)) {
48
+ return PHP_BINARY.$args;
49
+ }
50
+
51
+ if ($php = getenv('PHP_PATH')) {
52
+ if (!is_executable($php)) {
53
+ return false;
54
+ }
55
+
56
+ return $php;
57
+ }
58
+
59
+ if ($php = getenv('PHP_PEAR_PHP_BIN')) {
60
+ if (is_executable($php)) {
61
+ return $php;
62
+ }
63
+ }
64
+
65
+ $dirs = array(PHP_BINDIR);
66
+ if ('\\' === DIRECTORY_SEPARATOR) {
67
+ $dirs[] = 'C:\xampp\php\\';
68
+ }
69
+
70
+ return $this->executableFinder->find('php', false, $dirs);
71
+ }
72
+
73
+ /**
74
+ * Finds the PHP executable arguments.
75
+ *
76
+ * @return array The PHP executable arguments
77
+ */
78
+ public function findArguments()
79
+ {
80
+ $arguments = array();
81
+
82
+ if (defined('HHVM_VERSION')) {
83
+ $arguments[] = '--php';
84
+ } elseif ('phpdbg' === PHP_SAPI) {
85
+ $arguments[] = '-qrr';
86
+ }
87
+
88
+ return $arguments;
89
+ }
90
+ }
vendor/symfony/process/PhpProcess.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process;
13
+
14
+ use Symfony\Component\Process\Exception\RuntimeException;
15
+
16
+ /**
17
+ * PhpProcess runs a PHP script in an independent process.
18
+ *
19
+ * $p = new PhpProcess('<?php echo "foo"; ?>');
20
+ * $p->run();
21
+ * print $p->getOutput()."\n";
22
+ *
23
+ * @author Fabien Potencier <fabien@symfony.com>
24
+ */
25
+ class PhpProcess extends Process
26
+ {
27
+ /**
28
+ * Constructor.
29
+ *
30
+ * @param string $script The PHP script to run (as a string)
31
+ * @param string|null $cwd The working directory or null to use the working dir of the current PHP process
32
+ * @param array|null $env The environment variables or null to use the same environment as the current PHP process
33
+ * @param int $timeout The timeout in seconds
34
+ * @param array $options An array of options for proc_open
35
+ */
36
+ public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = array())
37
+ {
38
+ $executableFinder = new PhpExecutableFinder();
39
+ if (false === $php = $executableFinder->find()) {
40
+ $php = null;
41
+ }
42
+ if ('phpdbg' === PHP_SAPI) {
43
+ $file = tempnam(sys_get_temp_dir(), 'dbg');
44
+ file_put_contents($file, $script);
45
+ register_shutdown_function('unlink', $file);
46
+ $php .= ' '.ProcessUtils::escapeArgument($file);
47
+ $script = null;
48
+ }
49
+ if ('\\' !== DIRECTORY_SEPARATOR && null !== $php) {
50
+ // exec is mandatory to deal with sending a signal to the process
51
+ // see https://github.com/symfony/symfony/issues/5030 about prepending
52
+ // command with exec
53
+ $php = 'exec '.$php;
54
+ }
55
+
56
+ parent::__construct($php, $cwd, $env, $script, $timeout, $options);
57
+ }
58
+
59
+ /**
60
+ * Sets the path to the PHP binary to use.
61
+ */
62
+ public function setPhpBinary($php)
63
+ {
64
+ $this->setCommandLine($php);
65
+ }
66
+
67
+ /**
68
+ * {@inheritdoc}
69
+ */
70
+ public function start($callback = null)
71
+ {
72
+ if (null === $this->getCommandLine()) {
73
+ throw new RuntimeException('Unable to find the PHP executable.');
74
+ }
75
+
76
+ parent::start($callback);
77
+ }
78
+ }
vendor/symfony/process/Pipes/AbstractPipes.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Pipes;
13
+
14
+ /**
15
+ * @author Romain Neutron <imprec@gmail.com>
16
+ *
17
+ * @internal
18
+ */
19
+ abstract class AbstractPipes implements PipesInterface
20
+ {
21
+ /** @var array */
22
+ public $pipes = array();
23
+
24
+ /** @var string */
25
+ protected $inputBuffer = '';
26
+ /** @var resource|null */
27
+ protected $input;
28
+
29
+ /** @var bool */
30
+ private $blocked = true;
31
+
32
+ /**
33
+ * {@inheritdoc}
34
+ */
35
+ public function close()
36
+ {
37
+ foreach ($this->pipes as $pipe) {
38
+ fclose($pipe);
39
+ }
40
+ $this->pipes = array();
41
+ }
42
+
43
+ /**
44
+ * Returns true if a system call has been interrupted.
45
+ *
46
+ * @return bool
47
+ */
48
+ protected function hasSystemCallBeenInterrupted()
49
+ {
50
+ $lastError = error_get_last();
51
+
52
+ // stream_select returns false when the `select` system call is interrupted by an incoming signal
53
+ return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
54
+ }
55
+
56
+ /**
57
+ * Unblocks streams.
58
+ */
59
+ protected function unblock()
60
+ {
61
+ if (!$this->blocked) {
62
+ return;
63
+ }
64
+
65
+ foreach ($this->pipes as $pipe) {
66
+ stream_set_blocking($pipe, 0);
67
+ }
68
+ if (null !== $this->input) {
69
+ stream_set_blocking($this->input, 0);
70
+ }
71
+
72
+ $this->blocked = false;
73
+ }
74
+ }
vendor/symfony/process/Pipes/PipesInterface.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Pipes;
13
+
14
+ /**
15
+ * PipesInterface manages descriptors and pipes for the use of proc_open.
16
+ *
17
+ * @author Romain Neutron <imprec@gmail.com>
18
+ *
19
+ * @internal
20
+ */
21
+ interface PipesInterface
22
+ {
23
+ const CHUNK_SIZE = 16384;
24
+
25
+ /**
26
+ * Returns an array of descriptors for the use of proc_open.
27
+ *
28
+ * @return array
29
+ */
30
+ public function getDescriptors();
31
+
32
+ /**
33
+ * Returns an array of filenames indexed by their related stream in case these pipes use temporary files.
34
+ *
35
+ * @return string[]
36
+ */
37
+ public function getFiles();
38
+
39
+ /**
40
+ * Reads data in file handles and pipes.
41
+ *
42
+ * @param bool $blocking Whether to use blocking calls or not.
43
+ * @param bool $close Whether to close pipes if they've reached EOF.
44
+ *
45
+ * @return string[] An array of read data indexed by their fd.
46
+ */
47
+ public function readAndWrite($blocking, $close = false);
48
+
49
+ /**
50
+ * Returns if the current state has open file handles or pipes.
51
+ *
52
+ * @return bool
53
+ */
54
+ public function areOpen();
55
+
56
+ /**
57
+ * Closes file handles and pipes.
58
+ */
59
+ public function close();
60
+ }
vendor/symfony/process/Pipes/UnixPipes.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Pipes;
13
+
14
+ use Symfony\Component\Process\Process;
15
+
16
+ /**
17
+ * UnixPipes implementation uses unix pipes as handles.
18
+ *
19
+ * @author Romain Neutron <imprec@gmail.com>
20
+ *
21
+ * @internal
22
+ */
23
+ class UnixPipes extends AbstractPipes
24
+ {
25
+ /** @var bool */
26
+ private $ttyMode;
27
+ /** @var bool */
28
+ private $ptyMode;
29
+ /** @var bool */
30
+ private $disableOutput;
31
+
32
+ public function __construct($ttyMode, $ptyMode, $input, $disableOutput)
33
+ {
34
+ $this->ttyMode = (bool) $ttyMode;
35
+ $this->ptyMode = (bool) $ptyMode;
36
+ $this->disableOutput = (bool) $disableOutput;
37
+
38
+ if (is_resource($input)) {
39
+ $this->input = $input;
40
+ } else {
41
+ $this->inputBuffer = (string) $input;
42
+ }
43
+ }
44
+
45
+ public function __destruct()
46
+ {
47
+ $this->close();
48
+ }
49
+
50
+ /**
51
+ * {@inheritdoc}
52
+ */
53
+ public function getDescriptors()
54
+ {
55
+ if ($this->disableOutput) {
56
+ $nullstream = fopen('/dev/null', 'c');
57
+
58
+ return array(
59
+ array('pipe', 'r'),
60
+ $nullstream,
61
+ $nullstream,
62
+ );
63
+ }
64
+
65
+ if ($this->ttyMode) {
66
+ return array(
67
+ array('file', '/dev/tty', 'r'),
68
+ array('file', '/dev/tty', 'w'),
69
+ array('file', '/dev/tty', 'w'),
70
+ );
71
+ }
72
+
73
+ if ($this->ptyMode && Process::isPtySupported()) {
74
+ return array(
75
+ array('pty'),
76
+ array('pty'),
77
+ array('pty'),
78
+ );
79
+ }
80
+
81
+ return array(
82
+ array('pipe', 'r'),
83
+ array('pipe', 'w'), // stdout
84
+ array('pipe', 'w'), // stderr
85
+ );
86
+ }
87
+
88
+ /**
89
+ * {@inheritdoc}
90
+ */
91
+ public function getFiles()
92
+ {
93
+ return array();
94
+ }
95
+
96
+ /**
97
+ * {@inheritdoc}
98
+ */
99
+ public function readAndWrite($blocking, $close = false)
100
+ {
101
+ // only stdin is left open, job has been done !
102
+ // we can now close it
103
+ if (1 === count($this->pipes) && array(0) === array_keys($this->pipes)) {
104
+ fclose($this->pipes[0]);
105
+ unset($this->pipes[0]);
106
+ }
107
+
108
+ if (empty($this->pipes)) {
109
+ return array();
110
+ }
111
+
112
+ $this->unblock();
113
+
114
+ $read = array();
115
+
116
+ if (null !== $this->input) {
117
+ // if input is a resource, let's add it to stream_select argument to
118
+ // fill a buffer
119
+ $r = array_merge($this->pipes, array('input' => $this->input));
120
+ } else {
121
+ $r = $this->pipes;
122
+ }
123
+ // discard read on stdin
124
+ unset($r[0]);
125
+
126
+ $w = isset($this->pipes[0]) ? array($this->pipes[0]) : null;
127
+ $e = null;
128
+
129
+ // let's have a look if something changed in streams
130
+ if (false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
131
+ // if a system call has been interrupted, forget about it, let's try again
132
+ // otherwise, an error occurred, let's reset pipes
133
+ if (!$this->hasSystemCallBeenInterrupted()) {
134
+ $this->pipes = array();
135
+ }
136
+
137
+ return $read;
138
+ }
139
+
140
+ // nothing has changed
141
+ if (0 === $n) {
142
+ return $read;
143
+ }
144
+
145
+ foreach ($r as $pipe) {
146
+ // prior PHP 5.4 the array passed to stream_select is modified and
147
+ // lose key association, we have to find back the key
148
+ $type = (false !== $found = array_search($pipe, $this->pipes)) ? $found : 'input';
149
+ $data = '';
150
+ while ('' !== $dataread = (string) fread($pipe, self::CHUNK_SIZE)) {
151
+ $data .= $dataread;
152
+ }
153
+
154
+ if ('' !== $data) {
155
+ if ($type === 'input') {
156
+ $this->inputBuffer .= $data;
157
+ } else {
158
+ $read[$type] = $data;
159
+ }
160
+ }
161
+
162
+ if (false === $data || (true === $close && feof($pipe) && '' === $data)) {
163
+ if ($type === 'input') {
164
+ // no more data to read on input resource
165
+ // use an empty buffer in the next reads
166
+ $this->input = null;
167
+ } else {
168
+ fclose($this->pipes[$type]);
169
+ unset($this->pipes[$type]);
170
+ }
171
+ }
172
+ }
173
+
174
+ if (null !== $w && 0 < count($w)) {
175
+ while (strlen($this->inputBuffer)) {
176
+ $written = fwrite($w[0], $this->inputBuffer, 2 << 18); // write 512k
177
+ if ($written > 0) {
178
+ $this->inputBuffer = (string) substr($this->inputBuffer, $written);
179
+ } else {
180
+ break;
181
+ }
182
+ }
183
+ }
184
+
185
+ // no input to read on resource, buffer is empty and stdin still open
186
+ if ('' === $this->inputBuffer && null === $this->input && isset($this->pipes[0])) {
187
+ fclose($this->pipes[0]);
188
+ unset($this->pipes[0]);
189
+ }
190
+
191
+ return $read;
192
+ }
193
+
194
+ /**
195
+ * {@inheritdoc}
196
+ */
197
+ public function areOpen()
198
+ {
199
+ return (bool) $this->pipes;
200
+ }
201
+
202
+ /**
203
+ * Creates a new UnixPipes instance.
204
+ *
205
+ * @param Process $process
206
+ * @param string|resource $input
207
+ *
208
+ * @return UnixPipes
209
+ */
210
+ public static function create(Process $process, $input)
211
+ {
212
+ return new static($process->isTty(), $process->isPty(), $input, $process->isOutputDisabled());
213
+ }
214
+ }
vendor/symfony/process/Pipes/WindowsPipes.php ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Pipes;
13
+
14
+ use Symfony\Component\Process\Process;
15
+ use Symfony\Component\Process\Exception\RuntimeException;
16
+
17
+ /**
18
+ * WindowsPipes implementation uses temporary files as handles.
19
+ *
20
+ * @see https://bugs.php.net/bug.php?id=51800
21
+ * @see https://bugs.php.net/bug.php?id=65650
22
+ *
23
+ * @author Romain Neutron <imprec@gmail.com>
24
+ *
25
+ * @internal
26
+ */
27
+ class WindowsPipes extends AbstractPipes
28
+ {
29
+ /** @var array */
30
+ private $files = array();
31
+ /** @var array */
32
+ private $fileHandles = array();
33
+ /** @var array */
34
+ private $readBytes = array(
35
+ Process::STDOUT => 0,
36
+ Process::STDERR => 0,
37
+ );
38
+ /** @var bool */
39
+ private $disableOutput;
40
+
41
+ public function __construct($disableOutput, $input)
42
+ {
43
+ $this->disableOutput = (bool) $disableOutput;
44
+
45
+ if (!$this->disableOutput) {
46
+ // Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.
47
+ // Workaround for this problem is to use temporary files instead of pipes on Windows platform.
48
+ //
49
+ // @see https://bugs.php.net/bug.php?id=51800
50
+ $this->files = array(
51
+ Process::STDOUT => tempnam(sys_get_temp_dir(), 'out_sf_proc'),
52
+ Process::STDERR => tempnam(sys_get_temp_dir(), 'err_sf_proc'),
53
+ );
54
+ foreach ($this->files as $offset => $file) {
55
+ if (false === $file || false === $this->fileHandles[$offset] = fopen($file, 'rb')) {
56
+ throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
57
+ }
58
+ }
59
+ }
60
+
61
+ if (is_resource($input)) {
62
+ $this->input = $input;
63
+ } else {
64
+ $this->inputBuffer = $input;
65
+ }
66
+ }
67
+
68
+ public function __destruct()
69
+ {
70
+ $this->close();
71
+ $this->removeFiles();
72
+ }
73
+
74
+ /**
75
+ * {@inheritdoc}
76
+ */
77
+ public function getDescriptors()
78
+ {
79
+ if ($this->disableOutput) {
80
+ $nullstream = fopen('NUL', 'c');
81
+
82
+ return array(
83
+ array('pipe', 'r'),
84
+ $nullstream,
85
+ $nullstream,
86
+ );
87
+ }
88
+
89
+ // We're not using pipe on Windows platform as it hangs (https://bugs.php.net/bug.php?id=51800)
90
+ // We're not using file handles as it can produce corrupted output https://bugs.php.net/bug.php?id=65650
91
+ // So we redirect output within the commandline and pass the nul device to the process
92
+ return array(
93
+ array('pipe', 'r'),
94
+ array('file', 'NUL', 'w'),
95
+ array('file', 'NUL', 'w'),
96
+ );
97
+ }
98
+
99
+ /**
100
+ * {@inheritdoc}
101
+ */
102
+ public function getFiles()
103
+ {
104
+ return $this->files;
105
+ }
106
+
107
+ /**
108
+ * {@inheritdoc}
109
+ */
110
+ public function readAndWrite($blocking, $close = false)
111
+ {
112
+ $this->write($blocking, $close);
113
+
114
+ $read = array();
115
+ $fh = $this->fileHandles;
116
+ foreach ($fh as $type => $fileHandle) {
117
+ if (0 !== fseek($fileHandle, $this->readBytes[$type])) {
118
+ continue;
119
+ }
120
+ $data = '';
121
+ $dataread = null;
122
+ while (!feof($fileHandle)) {
123
+ if (false !== $dataread = fread($fileHandle, self::CHUNK_SIZE)) {
124
+ $data .= $dataread;
125
+ }
126
+ }
127
+ if (0 < $length = strlen($data)) {
128
+ $this->readBytes[$type] += $length;
129
+ $read[$type] = $data;
130
+ }
131
+
132
+ if (false === $dataread || (true === $close && feof($fileHandle) && '' === $data)) {
133
+ fclose($this->fileHandles[$type]);
134
+ unset($this->fileHandles[$type]);
135
+ }
136
+ }
137
+
138
+ return $read;
139
+ }
140
+
141
+ /**
142
+ * {@inheritdoc}
143
+ */
144
+ public function areOpen()
145
+ {
146
+ return (bool) $this->pipes && (bool) $this->fileHandles;
147
+ }
148
+
149
+ /**
150
+ * {@inheritdoc}
151
+ */
152
+ public function close()
153
+ {
154
+ parent::close();
155
+ foreach ($this->fileHandles as $handle) {
156
+ fclose($handle);
157
+ }
158
+ $this->fileHandles = array();
159
+ }
160
+
161
+ /**
162
+ * Creates a new WindowsPipes instance.
163
+ *
164
+ * @param Process $process The process
165
+ * @param $input
166
+ *
167
+ * @return WindowsPipes
168
+ */
169
+ public static function create(Process $process, $input)
170
+ {
171
+ return new static($process->isOutputDisabled(), $input);
172
+ }
173
+
174
+ /**
175
+ * Removes temporary files.
176
+ */
177
+ private function removeFiles()
178
+ {
179
+ foreach ($this->files as $filename) {
180
+ if (file_exists($filename)) {
181
+ @unlink($filename);
182
+ }
183
+ }
184
+ $this->files = array();
185
+ }
186
+
187
+ /**
188
+ * Writes input to stdin.
189
+ *
190
+ * @param bool $blocking
191
+ * @param bool $close
192
+ */
193
+ private function write($blocking, $close)
194
+ {
195
+ if (empty($this->pipes)) {
196
+ return;
197
+ }
198
+
199
+ $this->unblock();
200
+
201
+ $r = null !== $this->input ? array('input' => $this->input) : null;
202
+ $w = isset($this->pipes[0]) ? array($this->pipes[0]) : null;
203
+ $e = null;
204
+
205
+ // let's have a look if something changed in streams
206
+ if (false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
207
+ // if a system call has been interrupted, forget about it, let's try again
208
+ // otherwise, an error occurred, let's reset pipes
209
+ if (!$this->hasSystemCallBeenInterrupted()) {
210
+ $this->pipes = array();
211
+ }
212
+
213
+ return;
214
+ }
215
+
216
+ // nothing has changed
217
+ if (0 === $n) {
218
+ return;
219
+ }
220
+
221
+ if (null !== $w && 0 < count($r)) {
222
+ $data = '';
223
+ while ($dataread = fread($r['input'], self::CHUNK_SIZE)) {
224
+ $data .= $dataread;
225
+ }
226
+
227
+ $this->inputBuffer .= $data;
228
+
229
+ if (false === $data || (true === $close && feof($r['input']) && '' === $data)) {
230
+ // no more data to read on input resource
231
+ // use an empty buffer in the next reads
232
+ $this->input = null;
233
+ }
234
+ }
235
+
236
+ if (null !== $w && 0 < count($w)) {
237
+ while (strlen($this->inputBuffer)) {
238
+ $written = fwrite($w[0], $this->inputBuffer, 2 << 18);
239
+ if ($written > 0) {
240
+ $this->inputBuffer = (string) substr($this->inputBuffer, $written);
241
+ } else {
242
+ break;
243
+ }
244
+ }
245
+ }
246
+
247
+ // no input to read on resource, buffer is empty and stdin still open
248
+ if ('' === $this->inputBuffer && null === $this->input && isset($this->pipes[0])) {
249
+ fclose($this->pipes[0]);
250
+ unset($this->pipes[0]);
251
+ }
252
+ }
253
+ }
vendor/symfony/process/Process.php ADDED
@@ -0,0 +1,1507 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process;
13
+
14
+ use Symfony\Component\Process\Exception\InvalidArgumentException;
15
+ use Symfony\Component\Process\Exception\LogicException;
16
+ use Symfony\Component\Process\Exception\ProcessFailedException;
17
+ use Symfony\Component\Process\Exception\ProcessTimedOutException;
18
+ use Symfony\Component\Process\Exception\RuntimeException;
19
+ use Symfony\Component\Process\Pipes\PipesInterface;
20
+ use Symfony\Component\Process\Pipes\UnixPipes;
21
+ use Symfony\Component\Process\Pipes\WindowsPipes;
22
+
23
+ /**
24
+ * Process is a thin wrapper around proc_* functions to easily
25
+ * start independent PHP processes.
26
+ *
27
+ * @author Fabien Potencier <fabien@symfony.com>
28
+ * @author Romain Neutron <imprec@gmail.com>
29
+ */
30
+ class Process
31
+ {
32
+ const ERR = 'err';
33
+ const OUT = 'out';
34
+
35
+ const STATUS_READY = 'ready';
36
+ const STATUS_STARTED = 'started';
37
+ const STATUS_TERMINATED = 'terminated';
38
+
39
+ const STDIN = 0;
40
+ const STDOUT = 1;
41
+ const STDERR = 2;
42
+
43
+ // Timeout Precision in seconds.
44
+ const TIMEOUT_PRECISION = 0.2;
45
+
46
+ private $callback;
47
+ private $commandline;
48
+ private $cwd;
49
+ private $env;
50
+ private $input;
51
+ private $starttime;
52
+ private $lastOutputTime;
53
+ private $timeout;
54
+ private $idleTimeout;
55
+ private $options;
56
+ private $exitcode;
57
+ private $fallbackStatus = array();
58
+ private $processInformation;
59
+ private $outputDisabled = false;
60
+ private $stdout;
61
+ private $stderr;
62
+ private $enhanceWindowsCompatibility = true;
63
+ private $enhanceSigchildCompatibility;
64
+ private $process;
65
+ private $status = self::STATUS_READY;
66
+ private $incrementalOutputOffset = 0;
67
+ private $incrementalErrorOutputOffset = 0;
68
+ private $tty;
69
+ private $pty;
70
+
71
+ private $useFileHandles = false;
72
+ /** @var PipesInterface */
73
+ private $processPipes;
74
+
75
+ private $latestSignal;
76
+
77
+ private static $sigchild;
78
+
79
+ /**
80
+ * Exit codes translation table.
81
+ *
82
+ * User-defined errors must use exit codes in the 64-113 range.
83
+ *
84
+ * @var array
85
+ */
86
+ public static $exitCodes = array(
87
+ 0 => 'OK',
88
+ 1 => 'General error',
89
+ 2 => 'Misuse of shell builtins',
90
+
91
+ 126 => 'Invoked command cannot execute',
92
+ 127 => 'Command not found',
93
+ 128 => 'Invalid exit argument',
94
+
95
+ // signals
96
+ 129 => 'Hangup',
97
+ 130 => 'Interrupt',
98
+ 131 => 'Quit and dump core',
99
+ 132 => 'Illegal instruction',
100
+ 133 => 'Trace/breakpoint trap',
101
+ 134 => 'Process aborted',
102
+ 135 => 'Bus error: "access to undefined portion of memory object"',
103
+ 136 => 'Floating point exception: "erroneous arithmetic operation"',
104
+ 137 => 'Kill (terminate immediately)',
105
+ 138 => 'User-defined 1',
106
+ 139 => 'Segmentation violation',
107
+ 140 => 'User-defined 2',
108
+ 141 => 'Write to pipe with no one reading',
109
+ 142 => 'Signal raised by alarm',
110
+ 143 => 'Termination (request to terminate)',
111
+ // 144 - not defined
112
+ 145 => 'Child process terminated, stopped (or continued*)',
113
+ 146 => 'Continue if stopped',
114
+ 147 => 'Stop executing temporarily',
115
+ 148 => 'Terminal stop signal',
116
+ 149 => 'Background process attempting to read from tty ("in")',
117
+ 150 => 'Background process attempting to write to tty ("out")',
118
+ 151 => 'Urgent data available on socket',
119
+ 152 => 'CPU time limit exceeded',
120
+ 153 => 'File size limit exceeded',
121
+ 154 => 'Signal raised by timer counting virtual time: "virtual timer expired"',
122
+ 155 => 'Profiling timer expired',
123
+ // 156 - not defined
124
+ 157 => 'Pollable event',
125
+ // 158 - not defined
126
+ 159 => 'Bad syscall',
127
+ );
128
+
129
+ /**
130
+ * Constructor.
131
+ *
132
+ * @param string $commandline The command line to run
133
+ * @param string|null $cwd The working directory or null to use the working dir of the current PHP process
134
+ * @param array|null $env The environment variables or null to use the same environment as the current PHP process
135
+ * @param string|null $input The input
136
+ * @param int|float|null $timeout The timeout in seconds or null to disable
137
+ * @param array $options An array of options for proc_open
138
+ *
139
+ * @throws RuntimeException When proc_open is not installed
140
+ */
141
+ public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
142
+ {
143
+ if (!function_exists('proc_open')) {
144
+ throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
145
+ }
146
+
147
+ $this->commandline = $commandline;
148
+ $this->cwd = $cwd;
149
+
150
+ // on Windows, if the cwd changed via chdir(), proc_open defaults to the dir where PHP was started
151
+ // on Gnu/Linux, PHP builds with --enable-maintainer-zts are also affected
152
+ // @see : https://bugs.php.net/bug.php?id=51800
153
+ // @see : https://bugs.php.net/bug.php?id=50524
154
+ if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DIRECTORY_SEPARATOR)) {
155
+ $this->cwd = getcwd();
156
+ }
157
+ if (null !== $env) {
158
+ $this->setEnv($env);
159
+ }
160
+
161
+ $this->input = $input;
162
+ $this->setTimeout($timeout);
163
+ $this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
164
+ $this->pty = false;
165
+ $this->enhanceWindowsCompatibility = true;
166
+ $this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
167
+ $this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
168
+ }
169
+
170
+ public function __destruct()
171
+ {
172
+ $this->stop(0);
173
+ }
174
+
175
+ public function __clone()
176
+ {
177
+ $this->resetProcessData();
178
+ }
179
+
180
+ /**
181
+ * Runs the process.
182
+ *
183
+ * The callback receives the type of output (out or err) and
184
+ * some bytes from the output in real-time. It allows to have feedback
185
+ * from the independent process during execution.
186
+ *
187
+ * The STDOUT and STDERR are also available after the process is finished
188
+ * via the getOutput() and getErrorOutput() methods.
189
+ *
190
+ * @param callable|null $callback A PHP callback to run whenever there is some
191
+ * output available on STDOUT or STDERR
192
+ *
193
+ * @return int The exit status code
194
+ *
195
+ * @throws RuntimeException When process can't be launched
196
+ * @throws RuntimeException When process stopped after receiving signal
197
+ * @throws LogicException In case a callback is provided and output has been disabled
198
+ */
199
+ public function run($callback = null)
200
+ {
201
+ $this->start($callback);
202
+
203
+ return $this->wait();
204
+ }
205
+
206
+ /**
207
+ * Runs the process.
208
+ *
209
+ * This is identical to run() except that an exception is thrown if the process
210
+ * exits with a non-zero exit code.
211
+ *
212
+ * @param callable|null $callback
213
+ *
214
+ * @return self
215
+ *
216
+ * @throws RuntimeException if PHP was compiled with --enable-sigchild and the enhanced sigchild compatibility mode is not enabled
217
+ * @throws ProcessFailedException if the process didn't terminate successfully
218
+ */
219
+ public function mustRun($callback = null)
220
+ {
221
+ if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
222
+ throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
223
+ }
224
+
225
+ if (0 !== $this->run($callback)) {
226
+ throw new ProcessFailedException($this);
227
+ }
228
+
229
+ return $this;
230
+ }
231
+
232
+ /**
233
+ * Starts the process and returns after writing the input to STDIN.
234
+ *
235
+ * This method blocks until all STDIN data is sent to the process then it
236
+ * returns while the process runs in the background.
237
+ *
238
+ * The termination of the process can be awaited with wait().
239
+ *
240
+ * The callback receives the type of output (out or err) and some bytes from
241
+ * the output in real-time while writing the standard input to the process.
242
+ * It allows to have feedback from the independent process during execution.
243
+ *
244
+ * @param callable|null $callback A PHP callback to run whenever there is some
245
+ * output available on STDOUT or STDERR
246
+ *
247
+ * @throws RuntimeException When process can't be launched
248
+ * @throws RuntimeException When process is already running
249
+ * @throws LogicException In case a callback is provided and output has been disabled
250
+ */
251
+ public function start($callback = null)
252
+ {
253
+ if ($this->isRunning()) {
254
+ throw new RuntimeException('Process is already running');
255
+ }
256
+ if ($this->outputDisabled && null !== $callback) {
257
+ throw new LogicException('Output has been disabled, enable it to allow the use of a callback.');
258
+ }
259
+
260
+ $this->resetProcessData();
261
+ $this->starttime = $this->lastOutputTime = microtime(true);
262
+ $this->callback = $this->buildCallback($callback);
263
+ $descriptors = $this->getDescriptors();
264
+
265
+ $commandline = $this->commandline;
266
+
267
+ if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
268
+ $commandline = 'cmd /V:ON /E:ON /D /C "('.$commandline.')';
269
+ foreach ($this->processPipes->getFiles() as $offset => $filename) {
270
+ $commandline .= ' '.$offset.'>'.ProcessUtils::escapeArgument($filename);
271
+ }
272
+ $commandline .= '"';
273
+
274
+ if (!isset($this->options['bypass_shell'])) {
275
+ $this->options['bypass_shell'] = true;
276
+ }
277
+ } elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
278
+ // last exit code is output on the fourth pipe and caught to work around --enable-sigchild
279
+ $descriptors[3] = array('pipe', 'w');
280
+
281
+ // See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
282
+ $commandline = '{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
283
+ $commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code';
284
+
285
+ // Workaround for the bug, when PTS functionality is enabled.
286
+ // @see : https://bugs.php.net/69442
287
+ $ptsWorkaround = fopen(__FILE__, 'r');
288
+ }
289
+
290
+ $this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);
291
+
292
+ if (!is_resource($this->process)) {
293
+ throw new RuntimeException('Unable to launch a new process.');
294
+ }
295
+ $this->status = self::STATUS_STARTED;
296
+
297
+ if (isset($descriptors[3])) {
298
+ $this->fallbackStatus['pid'] = (int) fgets($this->processPipes->pipes[3]);
299
+ }
300
+
301
+ if ($this->tty) {
302
+ return;
303
+ }
304
+
305
+ $this->updateStatus(false);
306
+ $this->checkTimeout();
307
+ }
308
+
309
+ /**
310
+ * Restarts the process.
311
+ *
312
+ * Be warned that the process is cloned before being started.
313
+ *
314
+ * @param callable|null $callback A PHP callback to run whenever there is some
315
+ * output available on STDOUT or STDERR
316
+ *
317
+ * @return Process The new process
318
+ *
319
+ * @throws RuntimeException When process can't be launched
320
+ * @throws RuntimeException When process is already running
321
+ *
322
+ * @see start()
323
+ */
324
+ public function restart($callback = null)
325
+ {
326
+ if ($this->isRunning()) {
327
+ throw new RuntimeException('Process is already running');
328
+ }
329
+
330
+ $process = clone $this;
331
+ $process->start($callback);
332
+
333
+ return $process;
334
+ }
335
+
336
+ /**
337
+ * Waits for the process to terminate.
338
+ *
339
+ * The callback receives the type of output (out or err) and some bytes
340
+ * from the output in real-time while writing the standard input to the process.
341
+ * It allows to have feedback from the independent process during execution.
342
+ *
343
+ * @param callable|null $callback A valid PHP callback
344
+ *
345
+ * @return int The exitcode of the process
346
+ *
347
+ * @throws RuntimeException When process timed out
348
+ * @throws RuntimeException When process stopped after receiving signal
349
+ * @throws LogicException When process is not yet started
350
+ */
351
+ public function wait($callback = null)
352
+ {
353
+ $this->requireProcessIsStarted(__FUNCTION__);
354
+
355
+ $this->updateStatus(false);
356
+ if (null !== $callback) {
357
+ $this->callback = $this->buildCallback($callback);
358
+ }
359
+
360
+ do {
361
+ $this->checkTimeout();
362
+ $running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
363
+ $close = '\\' !== DIRECTORY_SEPARATOR || !$running;
364
+ $this->readPipes(true, $close);
365
+ } while ($running);
366
+
367
+ while ($this->isRunning()) {
368
+ usleep(1000);
369
+ }
370
+
371
+ if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
372
+ throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
373
+ }
374
+
375
+ return $this->exitcode;
376
+ }
377
+
378
+ /**
379
+ * Returns the Pid (process identifier), if applicable.
380
+ *
381
+ * @return int|null The process id if running, null otherwise
382
+ */
383
+ public function getPid()
384
+ {
385
+ return $this->isRunning() ? $this->processInformation['pid'] : null;
386
+ }
387
+
388
+ /**
389
+ * Sends a POSIX signal to the process.
390
+ *
391
+ * @param int $signal A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
392
+ *
393
+ * @return Process
394
+ *
395
+ * @throws LogicException In case the process is not running
396
+ * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
397
+ * @throws RuntimeException In case of failure
398
+ */
399
+ public function signal($signal)
400
+ {
401
+ $this->doSignal($signal, true);
402
+
403
+ return $this;
404
+ }
405
+
406
+ /**
407
+ * Disables fetching output and error output from the underlying process.
408
+ *
409
+ * @return Process
410
+ *
411
+ * @throws RuntimeException In case the process is already running
412
+ * @throws LogicException if an idle timeout is set
413
+ */
414
+ public function disableOutput()
415
+ {
416
+ if ($this->isRunning()) {
417
+ throw new RuntimeException('Disabling output while the process is running is not possible.');
418
+ }
419
+ if (null !== $this->idleTimeout) {
420
+ throw new LogicException('Output can not be disabled while an idle timeout is set.');
421
+ }
422
+
423
+ $this->outputDisabled = true;
424
+
425
+ return $this;
426
+ }
427
+
428
+ /**
429
+ * Enables fetching output and error output from the underlying process.
430
+ *
431
+ * @return Process
432
+ *
433
+ * @throws RuntimeException In case the process is already running
434
+ */
435
+ public function enableOutput()
436
+ {
437
+ if ($this->isRunning()) {
438
+ throw new RuntimeException('Enabling output while the process is running is not possible.');
439
+ }
440
+
441
+ $this->outputDisabled = false;
442
+
443
+ return $this;
444
+ }
445
+
446
+ /**
447
+ * Returns true in case the output is disabled, false otherwise.
448
+ *
449
+ * @return bool
450
+ */
451
+ public function isOutputDisabled()
452
+ {
453
+ return $this->outputDisabled;
454
+ }
455
+
456
+ /**
457
+ * Returns the current output of the process (STDOUT).
458
+ *
459
+ * @return string The process output
460
+ *
461
+ * @throws LogicException in case the output has been disabled
462
+ * @throws LogicException In case the process is not started
463
+ */
464
+ public function getOutput()
465
+ {
466
+ if ($this->outputDisabled) {
467
+ throw new LogicException('Output has been disabled.');
468
+ }
469
+
470
+ $this->requireProcessIsStarted(__FUNCTION__);
471
+
472
+ $this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
473
+
474
+ if (false === $ret = stream_get_contents($this->stdout, -1, 0)) {
475
+ return '';
476
+ }
477
+
478
+ return $ret;
479
+ }
480
+
481
+ /**
482
+ * Returns the output incrementally.
483
+ *
484
+ * In comparison with the getOutput method which always return the whole
485
+ * output, this one returns the new output since the last call.
486
+ *
487
+ * @throws LogicException in case the output has been disabled
488
+ * @throws LogicException In case the process is not started
489
+ *
490
+ * @return string The process output since the last call
491
+ */
492
+ public function getIncrementalOutput()
493
+ {
494
+ if ($this->outputDisabled) {
495
+ throw new LogicException('Output has been disabled.');
496
+ }
497
+
498
+ $this->requireProcessIsStarted(__FUNCTION__);
499
+
500
+ $latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
501
+ $this->incrementalOutputOffset = ftell($this->stdout);
502
+
503
+ if (false === $latest) {
504
+ return '';
505
+ }
506
+
507
+ return $latest;
508
+ }
509
+
510
+ /**
511
+ * Clears the process output.
512
+ *
513
+ * @return Process
514
+ */
515
+ public function clearOutput()
516
+ {
517
+ ftruncate($this->stdout, 0);
518
+ fseek($this->stdout, 0);
519
+ $this->incrementalOutputOffset = 0;
520
+
521
+ return $this;
522
+ }
523
+
524
+ /**
525
+ * Returns the current error output of the process (STDERR).
526
+ *
527
+ * @return string The process error output
528
+ *
529
+ * @throws LogicException in case the output has been disabled
530
+ * @throws LogicException In case the process is not started
531
+ */
532
+ public function getErrorOutput()
533
+ {
534
+ if ($this->outputDisabled) {
535
+ throw new LogicException('Output has been disabled.');
536
+ }
537
+
538
+ $this->requireProcessIsStarted(__FUNCTION__);
539
+
540
+ $this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
541
+
542
+ if (false === $ret = stream_get_contents($this->stderr, -1, 0)) {
543
+ return '';
544
+ }
545
+
546
+ return $ret;
547
+ }
548
+
549
+ /**
550
+ * Returns the errorOutput incrementally.
551
+ *
552
+ * In comparison with the getErrorOutput method which always return the
553
+ * whole error output, this one returns the new error output since the last
554
+ * call.
555
+ *
556
+ * @throws LogicException in case the output has been disabled
557
+ * @throws LogicException In case the process is not started
558
+ *
559
+ * @return string The process error output since the last call
560
+ */
561
+ public function getIncrementalErrorOutput()
562
+ {
563
+ if ($this->outputDisabled) {
564
+ throw new LogicException('Output has been disabled.');
565
+ }
566
+
567
+ $this->requireProcessIsStarted(__FUNCTION__);
568
+
569
+ $latest = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);
570
+ $this->incrementalErrorOutputOffset = ftell($this->stderr);
571
+
572
+ if (false === $latest) {
573
+ return '';
574
+ }
575
+
576
+ return $latest;
577
+ }
578
+
579
+ /**
580
+ * Clears the process output.
581
+ *
582
+ * @return Process
583
+ */
584
+ public function clearErrorOutput()
585
+ {
586
+ ftruncate($this->stderr, 0);
587
+ fseek($this->stderr, 0);
588
+ $this->incrementalErrorOutputOffset = 0;
589
+
590
+ return $this;
591
+ }
592
+
593
+ /**
594
+ * Returns the exit code returned by the process.
595
+ *
596
+ * @return null|int The exit status code, null if the Process is not terminated
597
+ *
598
+ * @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
599
+ */
600
+ public function getExitCode()
601
+ {
602
+ if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
603
+ throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
604
+ }
605
+
606
+ $this->updateStatus(false);
607
+
608
+ return $this->exitcode;
609
+ }
610
+
611
+ /**
612
+ * Returns a string representation for the exit code returned by the process.
613
+ *
614
+ * This method relies on the Unix exit code status standardization
615
+ * and might not be relevant for other operating systems.
616
+ *
617
+ * @return null|string A string representation for the exit status code, null if the Process is not terminated.
618
+ *
619
+ * @see http://tldp.org/LDP/abs/html/exitcodes.html
620
+ * @see http://en.wikipedia.org/wiki/Unix_signal
621
+ */
622
+ public function getExitCodeText()
623
+ {
624
+ if (null === $exitcode = $this->getExitCode()) {
625
+ return;
626
+ }
627
+
628
+ return isset(self::$exitCodes[$exitcode]) ? self::$exitCodes[$exitcode] : 'Unknown error';
629
+ }
630
+
631
+ /**
632
+ * Checks if the process ended successfully.
633
+ *
634
+ * @return bool true if the process ended successfully, false otherwise
635
+ */
636
+ public function isSuccessful()
637
+ {
638
+ return 0 === $this->getExitCode();
639
+ }
640
+
641
+ /**
642
+ * Returns true if the child process has been terminated by an uncaught signal.
643
+ *
644
+ * It always returns false on Windows.
645
+ *
646
+ * @return bool
647
+ *
648
+ * @throws RuntimeException In case --enable-sigchild is activated
649
+ * @throws LogicException In case the process is not terminated
650
+ */
651
+ public function hasBeenSignaled()
652
+ {
653
+ $this->requireProcessIsTerminated(__FUNCTION__);
654
+
655
+ if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
656
+ throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
657
+ }
658
+
659
+ return $this->processInformation['signaled'];
660
+ }
661
+
662
+ /**
663
+ * Returns the number of the signal that caused the child process to terminate its execution.
664
+ *
665
+ * It is only meaningful if hasBeenSignaled() returns true.
666
+ *
667
+ * @return int
668
+ *
669
+ * @throws RuntimeException In case --enable-sigchild is activated
670
+ * @throws LogicException In case the process is not terminated
671
+ */
672
+ public function getTermSignal()
673
+ {
674
+ $this->requireProcessIsTerminated(__FUNCTION__);
675
+
676
+ if ($this->isSigchildEnabled() && (!$this->enhanceSigchildCompatibility || -1 === $this->processInformation['termsig'])) {
677
+ throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
678
+ }
679
+
680
+ return $this->processInformation['termsig'];
681
+ }
682
+
683
+ /**
684
+ * Returns true if the child process has been stopped by a signal.
685
+ *
686
+ * It always returns false on Windows.
687
+ *
688
+ * @return bool
689
+ *
690
+ * @throws LogicException In case the process is not terminated
691
+ */
692
+ public function hasBeenStopped()
693
+ {
694
+ $this->requireProcessIsTerminated(__FUNCTION__);
695
+
696
+ return $this->processInformation['stopped'];
697
+ }
698
+
699
+ /**
700
+ * Returns the number of the signal that caused the child process to stop its execution.
701
+ *
702
+ * It is only meaningful if hasBeenStopped() returns true.
703
+ *
704
+ * @return int
705
+ *
706
+ * @throws LogicException In case the process is not terminated
707
+ */
708
+ public function getStopSignal()
709
+ {
710
+ $this->requireProcessIsTerminated(__FUNCTION__);
711
+
712
+ return $this->processInformation['stopsig'];
713
+ }
714
+
715
+ /**
716
+ * Checks if the process is currently running.
717
+ *
718
+ * @return bool true if the process is currently running, false otherwise
719
+ */
720
+ public function isRunning()
721
+ {
722
+ if (self::STATUS_STARTED !== $this->status) {
723
+ return false;
724
+ }
725
+
726
+ $this->updateStatus(false);
727
+
728
+ return $this->processInformation['running'];
729
+ }
730
+
731
+ /**
732
+ * Checks if the process has been started with no regard to the current state.
733
+ *
734
+ * @return bool true if status is ready, false otherwise
735
+ */
736
+ public function isStarted()
737
+ {
738
+ return $this->status != self::STATUS_READY;
739
+ }
740
+
741
+ /**
742
+ * Checks if the process is terminated.
743
+ *
744
+ * @return bool true if process is terminated, false otherwise
745
+ */
746
+ public function isTerminated()
747
+ {
748
+ $this->updateStatus(false);
749
+
750
+ return $this->status == self::STATUS_TERMINATED;
751
+ }
752
+
753
+ /**
754
+ * Gets the process status.
755
+ *
756
+ * The status is one of: ready, started, terminated.
757
+ *
758
+ * @return string The current process status
759
+ */
760
+ public function getStatus()
761
+ {
762
+ $this->updateStatus(false);
763
+
764
+ return $this->status;
765
+ }
766
+
767
+ /**
768
+ * Stops the process.
769
+ *
770
+ * @param int|float $timeout The timeout in seconds
771
+ * @param int $signal A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL (9)
772
+ *
773
+ * @return int The exit-code of the process
774
+ */
775
+ public function stop($timeout = 10, $signal = null)
776
+ {
777
+ $timeoutMicro = microtime(true) + $timeout;
778
+ if ($this->isRunning()) {
779
+ // given `SIGTERM` may not be defined and that `proc_terminate` uses the constant value and not the constant itself, we use the same here
780
+ $this->doSignal(15, false);
781
+ do {
782
+ usleep(1000);
783
+ } while ($this->isRunning() && microtime(true) < $timeoutMicro);
784
+
785
+ if ($this->isRunning()) {
786
+ // Avoid exception here: process is supposed to be running, but it might have stopped just
787
+ // after this line. In any case, let's silently discard the error, we cannot do anything.
788
+ $this->doSignal($signal ?: 9, false);
789
+ }
790
+ }
791
+
792
+ if ($this->isRunning()) {
793
+ if (isset($this->fallbackStatus['pid'])) {
794
+ unset($this->fallbackStatus['pid']);
795
+
796
+ return $this->stop(0, $signal);
797
+ }
798
+ $this->close();
799
+ }
800
+
801
+ return $this->exitcode;
802
+ }
803
+
804
+ /**
805
+ * Adds a line to the STDOUT stream.
806
+ *
807
+ * @internal
808
+ *
809
+ * @param string $line The line to append
810
+ */
811
+ public function addOutput($line)
812
+ {
813
+ $this->lastOutputTime = microtime(true);
814
+
815
+ fseek($this->stdout, 0, SEEK_END);
816
+ fwrite($this->stdout, $line);
817
+ fseek($this->stdout, $this->incrementalOutputOffset);
818
+ }
819
+
820
+ /**
821
+ * Adds a line to the STDERR stream.
822
+ *
823
+ * @internal
824
+ *
825
+ * @param string $line The line to append
826
+ */
827
+ public function addErrorOutput($line)
828
+ {
829
+ $this->lastOutputTime = microtime(true);
830
+
831
+ fseek($this->stderr, 0, SEEK_END);
832
+ fwrite($this->stderr, $line);
833
+ fseek($this->stderr, $this->incrementalErrorOutputOffset);
834
+ }
835
+
836
+ /**
837
+ * Gets the command line to be executed.
838
+ *
839
+ * @return string The command to execute
840
+ */
841
+ public function getCommandLine()
842
+ {
843
+ return $this->commandline;
844
+ }
845
+
846
+ /**
847
+ * Sets the command line to be executed.
848
+ *
849
+ * @param string $commandline The command to execute
850
+ *
851
+ * @return self The current Process instance
852
+ */
853
+ public function setCommandLine($commandline)
854
+ {
855
+ $this->commandline = $commandline;
856
+
857
+ return $this;
858
+ }
859
+
860
+ /**
861
+ * Gets the process timeout (max. runtime).
862
+ *
863
+ * @return float|null The timeout in seconds or null if it's disabled
864
+ */
865
+ public function getTimeout()
866
+ {
867
+ return $this->timeout;
868
+ }
869
+
870
+ /**
871
+ * Gets the process idle timeout (max. time since last output).
872
+ *
873
+ * @return float|null The timeout in seconds or null if it's disabled
874
+ */
875
+ public function getIdleTimeout()
876
+ {
877
+ return $this->idleTimeout;
878
+ }
879
+
880
+ /**
881
+ * Sets the process timeout (max. runtime).
882
+ *
883
+ * To disable the timeout, set this value to null.
884
+ *
885
+ * @param int|float|null $timeout The timeout in seconds
886
+ *
887
+ * @return self The current Process instance
888
+ *
889
+ * @throws InvalidArgumentException if the timeout is negative
890
+ */
891
+ public function setTimeout($timeout)
892
+ {
893
+ $this->timeout = $this->validateTimeout($timeout);
894
+
895
+ return $this;
896
+ }
897
+
898
+ /**
899
+ * Sets the process idle timeout (max. time since last output).
900
+ *
901
+ * To disable the timeout, set this value to null.
902
+ *
903
+ * @param int|float|null $timeout The timeout in seconds
904
+ *
905
+ * @return self The current Process instance.
906
+ *
907
+ * @throws LogicException if the output is disabled
908
+ * @throws InvalidArgumentException if the timeout is negative
909
+ */
910
+ public function setIdleTimeout($timeout)
911
+ {
912
+ if (null !== $timeout && $this->outputDisabled) {
913
+ throw new LogicException('Idle timeout can not be set while the output is disabled.');
914
+ }
915
+
916
+ $this->idleTimeout = $this->validateTimeout($timeout);
917
+
918
+ return $this;
919
+ }
920
+
921
+ /**
922
+ * Enables or disables the TTY mode.
923
+ *
924
+ * @param bool $tty True to enabled and false to disable
925
+ *
926
+ * @return self The current Process instance
927
+ *
928
+ * @throws RuntimeException In case the TTY mode is not supported
929
+ */
930
+ public function setTty($tty)
931
+ {
932
+ if ('\\' === DIRECTORY_SEPARATOR && $tty) {
933
+ throw new RuntimeException('TTY mode is not supported on Windows platform.');
934
+ }
935
+ if ($tty && (!file_exists('/dev/tty') || !is_readable('/dev/tty'))) {
936
+ throw new RuntimeException('TTY mode requires /dev/tty to be readable.');
937
+ }
938
+
939
+ $this->tty = (bool) $tty;
940
+
941
+ return $this;
942
+ }
943
+
944
+ /**
945
+ * Checks if the TTY mode is enabled.
946
+ *
947
+ * @return bool true if the TTY mode is enabled, false otherwise
948
+ */
949
+ public function isTty()
950
+ {
951
+ return $this->tty;
952
+ }
953
+
954
+ /**
955
+ * Sets PTY mode.
956
+ *
957
+ * @param bool $bool
958
+ *
959
+ * @return self
960
+ */
961
+ public function setPty($bool)
962
+ {
963
+ $this->pty = (bool) $bool;
964
+
965
+ return $this;
966
+ }
967
+
968
+ /**
969
+ * Returns PTY state.
970
+ *
971
+ * @return bool
972
+ */
973
+ public function isPty()
974
+ {
975
+ return $this->pty;
976
+ }
977
+
978
+ /**
979
+ * Gets the working directory.
980
+ *
981
+ * @return string|null The current working directory or null on failure
982
+ */
983
+ public function getWorkingDirectory()
984
+ {
985
+ if (null === $this->cwd) {
986
+ // getcwd() will return false if any one of the parent directories does not have
987
+ // the readable or search mode set, even if the current directory does
988
+ return getcwd() ?: null;
989
+ }
990
+
991
+ return $this->cwd;
992
+ }
993
+
994
+ /**
995
+ * Sets the current working directory.
996
+ *
997
+ * @param string $cwd The new working directory
998
+ *
999
+ * @return self The current Process instance
1000
+ */
1001
+ public function setWorkingDirectory($cwd)
1002
+ {
1003
+ $this->cwd = $cwd;
1004
+
1005
+ return $this;
1006
+ }
1007
+
1008
+ /**
1009
+ * Gets the environment variables.
1010
+ *
1011
+ * @return array The current environment variables
1012
+ */
1013
+ public function getEnv()
1014
+ {
1015
+ return $this->env;
1016
+ }
1017
+
1018
+ /**
1019
+ * Sets the environment variables.
1020
+ *
1021
+ * An environment variable value should be a string.
1022
+ * If it is an array, the variable is ignored.
1023
+ *
1024
+ * That happens in PHP when 'argv' is registered into
1025
+ * the $_ENV array for instance.
1026
+ *
1027
+ * @param array $env The new environment variables
1028
+ *
1029
+ * @return self The current Process instance
1030
+ */
1031
+ public function setEnv(array $env)
1032
+ {
1033
+ // Process can not handle env values that are arrays
1034
+ $env = array_filter($env, function ($value) {
1035
+ return !is_array($value);
1036
+ });
1037
+
1038
+ $this->env = array();
1039
+ foreach ($env as $key => $value) {
1040
+ $this->env[$key] = (string) $value;
1041
+ }
1042
+
1043
+ return $this;
1044
+ }
1045
+
1046
+ /**
1047
+ * Gets the contents of STDIN.
1048
+ *
1049
+ * @return string|null The current contents
1050
+ *
1051
+ * @deprecated since version 2.5, to be removed in 3.0.
1052
+ * Use setInput() instead.
1053
+ * This method is deprecated in favor of getInput.
1054
+ */
1055
+ public function getStdin()
1056
+ {
1057
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the getInput() method instead.', E_USER_DEPRECATED);
1058
+
1059
+ return $this->getInput();
1060
+ }
1061
+
1062
+ /**
1063
+ * Gets the Process input.
1064
+ *
1065
+ * @return null|string The Process input
1066
+ */
1067
+ public function getInput()
1068
+ {
1069
+ return $this->input;
1070
+ }
1071
+
1072
+ /**
1073
+ * Sets the contents of STDIN.
1074
+ *
1075
+ * @param string|null $stdin The new contents
1076
+ *
1077
+ * @return self The current Process instance
1078
+ *
1079
+ * @deprecated since version 2.5, to be removed in 3.0.
1080
+ * Use setInput() instead.
1081
+ *
1082
+ * @throws LogicException In case the process is running
1083
+ * @throws InvalidArgumentException In case the argument is invalid
1084
+ */
1085
+ public function setStdin($stdin)
1086
+ {
1087
+ @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the setInput() method instead.', E_USER_DEPRECATED);
1088
+
1089
+ return $this->setInput($stdin);
1090
+ }
1091
+
1092
+ /**
1093
+ * Sets the input.
1094
+ *
1095
+ * This content will be passed to the underlying process standard input.
1096
+ *
1097
+ * @param mixed $input The content
1098
+ *
1099
+ * @return self The current Process instance
1100
+ *
1101
+ * @throws LogicException In case the process is running
1102
+ *
1103
+ * Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.
1104
+ */
1105
+ public function setInput($input)
1106
+ {
1107
+ if ($this->isRunning()) {
1108
+ throw new LogicException('Input can not be set while the process is running.');
1109
+ }
1110
+
1111
+ $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input);
1112
+
1113
+ return $this;
1114
+ }
1115
+
1116
+ /**
1117
+ * Gets the options for proc_open.
1118
+ *
1119
+ * @return array The current options
1120
+ */
1121
+ public function getOptions()
1122
+ {
1123
+ return $this->options;
1124
+ }
1125
+
1126
+ /**
1127
+ * Sets the options for proc_open.
1128
+ *
1129
+ * @param array $options The new options
1130
+ *
1131
+ * @return self The current Process instance
1132
+ */
1133
+ public function setOptions(array $options)
1134
+ {
1135
+ $this->options = $options;
1136
+
1137
+ return $this;
1138
+ }
1139
+
1140
+ /**
1141
+ * Gets whether or not Windows compatibility is enabled.
1142
+ *
1143
+ * This is true by default.
1144
+ *
1145
+ * @return bool
1146
+ */
1147
+ public function getEnhanceWindowsCompatibility()
1148
+ {
1149
+ return $this->enhanceWindowsCompatibility;
1150
+ }
1151
+
1152
+ /**
1153
+ * Sets whether or not Windows compatibility is enabled.
1154
+ *
1155
+ * @param bool $enhance
1156
+ *
1157
+ * @return self The current Process instance
1158
+ */
1159
+ public function setEnhanceWindowsCompatibility($enhance)
1160
+ {
1161
+ $this->enhanceWindowsCompatibility = (bool) $enhance;
1162
+
1163
+ return $this;
1164
+ }
1165
+
1166
+ /**
1167
+ * Returns whether sigchild compatibility mode is activated or not.
1168
+ *
1169
+ * @return bool
1170
+ */
1171
+ public function getEnhanceSigchildCompatibility()
1172
+ {
1173
+ return $this->enhanceSigchildCompatibility;
1174
+ }
1175
+
1176
+ /**
1177
+ * Activates sigchild compatibility mode.
1178
+ *
1179
+ * Sigchild compatibility mode is required to get the exit code and
1180
+ * determine the success of a process when PHP has been compiled with
1181
+ * the --enable-sigchild option
1182
+ *
1183
+ * @param bool $enhance
1184
+ *
1185
+ * @return self The current Process instance
1186
+ */
1187
+ public function setEnhanceSigchildCompatibility($enhance)
1188
+ {
1189
+ $this->enhanceSigchildCompatibility = (bool) $enhance;
1190
+
1191
+ return $this;
1192
+ }
1193
+
1194
+ /**
1195
+ * Performs a check between the timeout definition and the time the process started.
1196
+ *
1197
+ * In case you run a background process (with the start method), you should
1198
+ * trigger this method regularly to ensure the process timeout
1199
+ *
1200
+ * @throws ProcessTimedOutException In case the timeout was reached
1201
+ */
1202
+ public function checkTimeout()
1203
+ {
1204
+ if ($this->status !== self::STATUS_STARTED) {
1205
+ return;
1206
+ }
1207
+
1208
+ if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
1209
+ $this->stop(0);
1210
+
1211
+ throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL);
1212
+ }
1213
+
1214
+ if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
1215
+ $this->stop(0);
1216
+
1217
+ throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_IDLE);
1218
+ }
1219
+ }
1220
+
1221
+ /**
1222
+ * Returns whether PTY is supported on the current operating system.
1223
+ *
1224
+ * @return bool
1225
+ */
1226
+ public static function isPtySupported()
1227
+ {
1228
+ static $result;
1229
+
1230
+ if (null !== $result) {
1231
+ return $result;
1232
+ }
1233
+
1234
+ if ('\\' === DIRECTORY_SEPARATOR) {
1235
+ return $result = false;
1236
+ }
1237
+
1238
+ return $result = (bool) @proc_open('echo 1', array(array('pty'), array('pty'), array('pty')), $pipes);
1239
+ }
1240
+
1241
+ /**
1242
+ * Creates the descriptors needed by the proc_open.
1243
+ *
1244
+ * @return array
1245
+ */
1246
+ private function getDescriptors()
1247
+ {
1248
+ if ('\\' === DIRECTORY_SEPARATOR) {
1249
+ $this->processPipes = WindowsPipes::create($this, $this->input);
1250
+ } else {
1251
+ $this->processPipes = UnixPipes::create($this, $this->input);
1252
+ }
1253
+
1254
+ return $this->processPipes->getDescriptors();
1255
+ }
1256
+
1257
+ /**
1258
+ * Builds up the callback used by wait().
1259
+ *
1260
+ * The callbacks adds all occurred output to the specific buffer and calls
1261
+ * the user callback (if present) with the received output.
1262
+ *
1263
+ * @param callable|null $callback The user defined PHP callback
1264
+ *
1265
+ * @return \Closure A PHP closure
1266
+ */
1267
+ protected function buildCallback($callback)
1268
+ {
1269
+ $that = $this;
1270
+ $out = self::OUT;
1271
+ $callback = function ($type, $data) use ($that, $callback, $out) {
1272
+ if ($out == $type) {
1273
+ $that->addOutput($data);
1274
+ } else {
1275
+ $that->addErrorOutput($data);
1276
+ }
1277
+
1278
+ if (null !== $callback) {
1279
+ call_user_func($callback, $type, $data);
1280
+ }
1281
+ };
1282
+
1283
+ return $callback;
1284
+ }
1285
+
1286
+ /**
1287
+ * Updates the status of the process, reads pipes.
1288
+ *
1289
+ * @param bool $blocking Whether to use a blocking read call.
1290
+ */
1291
+ protected function updateStatus($blocking)
1292
+ {
1293
+ if (self::STATUS_STARTED !== $this->status) {
1294
+ return;
1295
+ }
1296
+
1297
+ $this->processInformation = proc_get_status($this->process);
1298
+
1299
+ $this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);
1300
+
1301
+ if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
1302
+ $this->processInformation = $this->fallbackStatus + $this->processInformation;
1303
+ }
1304
+
1305
+ if (!$this->processInformation['running']) {
1306
+ $this->close();
1307
+ }
1308
+ }
1309
+
1310
+ /**
1311
+ * Returns whether PHP has been compiled with the '--enable-sigchild' option or not.
1312
+ *
1313
+ * @return bool
1314
+ */
1315
+ protected function isSigchildEnabled()
1316
+ {
1317
+ if (null !== self::$sigchild) {
1318
+ return self::$sigchild;
1319
+ }
1320
+
1321
+ if (!function_exists('phpinfo') || defined('HHVM_VERSION')) {
1322
+ return self::$sigchild = false;
1323
+ }
1324
+
1325
+ ob_start();
1326
+ phpinfo(INFO_GENERAL);
1327
+
1328
+ return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
1329
+ }
1330
+
1331
+ /**
1332
+ * Validates and returns the filtered timeout.
1333
+ *
1334
+ * @param int|float|null $timeout
1335
+ *
1336
+ * @return float|null
1337
+ *
1338
+ * @throws InvalidArgumentException if the given timeout is a negative number
1339
+ */
1340
+ private function validateTimeout($timeout)
1341
+ {
1342
+ $timeout = (float) $timeout;
1343
+
1344
+ if (0.0 === $timeout) {
1345
+ $timeout = null;
1346
+ } elseif ($timeout < 0) {
1347
+ throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
1348
+ }
1349
+
1350
+ return $timeout;
1351
+ }
1352
+
1353
+ /**
1354
+ * Reads pipes, executes callback.
1355
+ *
1356
+ * @param bool $blocking Whether to use blocking calls or not.
1357
+ * @param bool $close Whether to close file handles or not.
1358
+ */
1359
+ private function readPipes($blocking, $close)
1360
+ {
1361
+ $result = $this->processPipes->readAndWrite($blocking, $close);
1362
+
1363
+ $callback = $this->callback;
1364
+ foreach ($result as $type => $data) {
1365
+ if (3 !== $type) {
1366
+ $callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
1367
+ } elseif (!isset($this->fallbackStatus['signaled'])) {
1368
+ $this->fallbackStatus['exitcode'] = (int) $data;
1369
+ }
1370
+ }
1371
+ }
1372
+
1373
+ /**
1374
+ * Closes process resource, closes file handles, sets the exitcode.
1375
+ *
1376
+ * @return int The exitcode
1377
+ */
1378
+ private function close()
1379
+ {
1380
+ $this->processPipes->close();
1381
+ if (is_resource($this->process)) {
1382
+ proc_close($this->process);
1383
+ }
1384
+ $this->exitcode = $this->processInformation['exitcode'];
1385
+ $this->status = self::STATUS_TERMINATED;
1386
+
1387
+ if (-1 === $this->exitcode) {
1388
+ if ($this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) {
1389
+ // if process has been signaled, no exitcode but a valid termsig, apply Unix convention
1390
+ $this->exitcode = 128 + $this->processInformation['termsig'];
1391
+ } elseif ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
1392
+ $this->processInformation['signaled'] = true;
1393
+ $this->processInformation['termsig'] = -1;
1394
+ }
1395
+ }
1396
+
1397
+ // Free memory from self-reference callback created by buildCallback
1398
+ // Doing so in other contexts like __destruct or by garbage collector is ineffective
1399
+ // Now pipes are closed, so the callback is no longer necessary
1400
+ $this->callback = null;
1401
+
1402
+ return $this->exitcode;
1403
+ }
1404
+
1405
+ /**
1406
+ * Resets data related to the latest run of the process.
1407
+ */
1408
+ private function resetProcessData()
1409
+ {
1410
+ $this->starttime = null;
1411
+ $this->callback = null;
1412
+ $this->exitcode = null;
1413
+ $this->fallbackStatus = array();
1414
+ $this->processInformation = null;
1415
+ $this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
1416
+ $this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
1417
+ $this->process = null;
1418
+ $this->latestSignal = null;
1419
+ $this->status = self::STATUS_READY;
1420
+ $this->incrementalOutputOffset = 0;
1421
+ $this->incrementalErrorOutputOffset = 0;
1422
+ }
1423
+
1424
+ /**
1425
+ * Sends a POSIX signal to the process.
1426
+ *
1427
+ * @param int $signal A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
1428
+ * @param bool $throwException Whether to throw exception in case signal failed
1429
+ *
1430
+ * @return bool True if the signal was sent successfully, false otherwise
1431
+ *
1432
+ * @throws LogicException In case the process is not running
1433
+ * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
1434
+ * @throws RuntimeException In case of failure
1435
+ */
1436
+ private function doSignal($signal, $throwException)
1437
+ {
1438
+ if (null === $pid = $this->getPid()) {
1439
+ if ($throwException) {
1440
+ throw new LogicException('Can not send signal on a non running process.');
1441
+ }
1442
+
1443
+ return false;
1444
+ }
1445
+
1446
+ if ('\\' === DIRECTORY_SEPARATOR) {
1447
+ exec(sprintf('taskkill /F /T /PID %d 2>&1', $pid), $output, $exitCode);
1448
+ if ($exitCode && $this->isRunning()) {
1449
+ if ($throwException) {
1450
+ throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output)));
1451
+ }
1452
+
1453
+ return false;
1454
+ }
1455
+ } else {
1456
+ if (!$this->enhanceSigchildCompatibility || !$this->isSigchildEnabled()) {
1457
+ $ok = @proc_terminate($this->process, $signal);
1458
+ } elseif (function_exists('posix_kill')) {
1459
+ $ok = @posix_kill($pid, $signal);
1460
+ } elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), array(2 => array('pipe', 'w')), $pipes)) {
1461
+ $ok = false === fgets($pipes[2]);
1462
+ }
1463
+ if (!$ok) {
1464
+ if ($throwException) {
1465
+ throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal));
1466
+ }
1467
+
1468
+ return false;
1469
+ }
1470
+ }
1471
+
1472
+ $this->latestSignal = (int) $signal;
1473
+ $this->fallbackStatus['signaled'] = true;
1474
+ $this->fallbackStatus['exitcode'] = -1;
1475
+ $this->fallbackStatus['termsig'] = $this->latestSignal;
1476
+
1477
+ return true;
1478
+ }
1479
+
1480
+ /**
1481
+ * Ensures the process is running or terminated, throws a LogicException if the process has a not started.
1482
+ *
1483
+ * @param string $functionName The function name that was called.
1484
+ *
1485
+ * @throws LogicException If the process has not run.
1486
+ */
1487
+ private function requireProcessIsStarted($functionName)
1488
+ {
1489
+ if (!$this->isStarted()) {
1490
+ throw new LogicException(sprintf('Process must be started before calling %s.', $functionName));
1491
+ }
1492
+ }
1493
+
1494
+ /**
1495
+ * Ensures the process is terminated, throws a LogicException if the process has a status different than `terminated`.
1496
+ *
1497
+ * @param string $functionName The function name that was called.
1498
+ *
1499
+ * @throws LogicException If the process is not yet terminated.
1500
+ */
1501
+ private function requireProcessIsTerminated($functionName)
1502
+ {
1503
+ if (!$this->isTerminated()) {
1504
+ throw new LogicException(sprintf('Process must be terminated before calling %s.', $functionName));
1505
+ }
1506
+ }
1507
+ }
vendor/symfony/process/ProcessBuilder.php ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process;
13
+
14
+ use Symfony\Component\Process\Exception\InvalidArgumentException;
15
+ use Symfony\Component\Process\Exception\LogicException;
16
+
17
+ /**
18
+ * Process builder.
19
+ *
20
+ * @author Kris Wallsmith <kris@symfony.com>
21
+ */
22
+ class ProcessBuilder
23
+ {
24
+ private $arguments;
25
+ private $cwd;
26
+ private $env = array();
27
+ private $input;
28
+ private $timeout = 60;
29
+ private $options = array();
30
+ private $inheritEnv = true;
31
+ private $prefix = array();
32
+ private $outputDisabled = false;
33
+
34
+ /**
35
+ * Constructor.
36
+ *
37
+ * @param string[] $arguments An array of arguments
38
+ */
39
+ public function __construct(array $arguments = array())
40
+ {
41
+ $this->arguments = $arguments;
42
+ }
43
+
44
+ /**
45
+ * Creates a process builder instance.
46
+ *
47
+ * @param string[] $arguments An array of arguments
48
+ *
49
+ * @return ProcessBuilder
50
+ */
51
+ public static function create(array $arguments = array())
52
+ {
53
+ return new static($arguments);
54
+ }
55
+
56
+ /**
57
+ * Adds an unescaped argument to the command string.
58
+ *
59
+ * @param string $argument A command argument
60
+ *
61
+ * @return ProcessBuilder
62
+ */
63
+ public function add($argument)
64
+ {
65
+ $this->arguments[] = $argument;
66
+
67
+ return $this;
68
+ }
69
+
70
+ /**
71
+ * Adds a prefix to the command string.
72
+ *
73
+ * The prefix is preserved when resetting arguments.
74
+ *
75
+ * @param string|array $prefix A command prefix or an array of command prefixes
76
+ *
77
+ * @return ProcessBuilder
78
+ */
79
+ public function setPrefix($prefix)
80
+ {
81
+ $this->prefix = is_array($prefix) ? $prefix : array($prefix);
82
+
83
+ return $this;
84
+ }
85
+
86
+ /**
87
+ * Sets the arguments of the process.
88
+ *
89
+ * Arguments must not be escaped.
90
+ * Previous arguments are removed.
91
+ *
92
+ * @param string[] $arguments
93
+ *
94
+ * @return ProcessBuilder
95
+ */
96
+ public function setArguments(array $arguments)
97
+ {
98
+ $this->arguments = $arguments;
99
+
100
+ return $this;
101
+ }
102
+
103
+ /**
104
+ * Sets the working directory.
105
+ *
106
+ * @param null|string $cwd The working directory
107
+ *
108
+ * @return ProcessBuilder
109
+ */
110
+ public function setWorkingDirectory($cwd)
111
+ {
112
+ $this->cwd = $cwd;
113
+
114
+ return $this;
115
+ }
116
+
117
+ /**
118
+ * Sets whether environment variables will be inherited or not.
119
+ *
120
+ * @param bool $inheritEnv
121
+ *
122
+ * @return ProcessBuilder
123
+ */
124
+ public function inheritEnvironmentVariables($inheritEnv = true)
125
+ {
126
+ $this->inheritEnv = $inheritEnv;
127
+
128
+ return $this;
129
+ }
130
+
131
+ /**
132
+ * Sets an environment variable.
133
+ *
134
+ * Setting a variable overrides its previous value. Use `null` to unset a
135
+ * defined environment variable.
136
+ *
137
+ * @param string $name The variable name
138
+ * @param null|string $value The variable value
139
+ *
140
+ * @return ProcessBuilder
141
+ */
142
+ public function setEnv($name, $value)
143
+ {
144
+ $this->env[$name] = $value;
145
+
146
+ return $this;
147
+ }
148
+
149
+ /**
150
+ * Adds a set of environment variables.
151
+ *
152
+ * Already existing environment variables with the same name will be
153
+ * overridden by the new values passed to this method. Pass `null` to unset
154
+ * a variable.
155
+ *
156
+ * @param array $variables The variables
157
+ *
158
+ * @return ProcessBuilder
159
+ */
160
+ public function addEnvironmentVariables(array $variables)
161
+ {
162
+ $this->env = array_replace($this->env, $variables);
163
+
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Sets the input of the process.
169
+ *
170
+ * @param mixed $input The input as a string
171
+ *
172
+ * @return ProcessBuilder
173
+ *
174
+ * @throws InvalidArgumentException In case the argument is invalid
175
+ *
176
+ * Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.
177
+ */
178
+ public function setInput($input)
179
+ {
180
+ $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input);
181
+
182
+ return $this;
183
+ }
184
+
185
+ /**
186
+ * Sets the process timeout.
187
+ *
188
+ * To disable the timeout, set this value to null.
189
+ *
190
+ * @param float|null $timeout
191
+ *
192
+ * @return ProcessBuilder
193
+ *
194
+ * @throws InvalidArgumentException
195
+ */
196
+ public function setTimeout($timeout)
197
+ {
198
+ if (null === $timeout) {
199
+ $this->timeout = null;
200
+
201
+ return $this;
202
+ }
203
+
204
+ $timeout = (float) $timeout;
205
+
206
+ if ($timeout < 0) {
207
+ throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
208
+ }
209
+
210
+ $this->timeout = $timeout;
211
+
212
+ return $this;
213
+ }
214
+
215
+ /**
216
+ * Adds a proc_open option.
217
+ *
218
+ * @param string $name The option name
219
+ * @param string $value The option value
220
+ *
221
+ * @return ProcessBuilder
222
+ */
223
+ public function setOption($name, $value)
224
+ {
225
+ $this->options[$name] = $value;
226
+
227
+ return $this;
228
+ }
229
+
230
+ /**
231
+ * Disables fetching output and error output from the underlying process.
232
+ *
233
+ * @return ProcessBuilder
234
+ */
235
+ public function disableOutput()
236
+ {
237
+ $this->outputDisabled = true;
238
+
239
+ return $this;
240
+ }
241
+
242
+ /**
243
+ * Enables fetching output and error output from the underlying process.
244
+ *
245
+ * @return ProcessBuilder
246
+ */
247
+ public function enableOutput()
248
+ {
249
+ $this->outputDisabled = false;
250
+
251
+ return $this;
252
+ }
253
+
254
+ /**
255
+ * Creates a Process instance and returns it.
256
+ *
257
+ * @return Process
258
+ *
259
+ * @throws LogicException In case no arguments have been provided
260
+ */
261
+ public function getProcess()
262
+ {
263
+ if (0 === count($this->prefix) && 0 === count($this->arguments)) {
264
+ throw new LogicException('You must add() command arguments before calling getProcess().');
265
+ }
266
+
267
+ $options = $this->options;
268
+
269
+ $arguments = array_merge($this->prefix, $this->arguments);
270
+ $script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));
271
+
272
+ if ($this->inheritEnv) {
273
+ // include $_ENV for BC purposes
274
+ $env = array_replace($_ENV, $_SERVER, $this->env);
275
+ } else {
276
+ $env = $this->env;
277
+ }
278
+
279
+ $process = new Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);
280
+
281
+ if ($this->outputDisabled) {
282
+ $process->disableOutput();
283
+ }
284
+
285
+ return $process;
286
+ }
287
+ }
vendor/symfony/process/ProcessUtils.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process;
13
+
14
+ use Symfony\Component\Process\Exception\InvalidArgumentException;
15
+
16
+ /**
17
+ * ProcessUtils is a bunch of utility methods.
18
+ *
19
+ * This class contains static methods only and is not meant to be instantiated.
20
+ *
21
+ * @author Martin Hasoň <martin.hason@gmail.com>
22
+ */
23
+ class ProcessUtils
24
+ {
25
+ /**
26
+ * This class should not be instantiated.
27
+ */
28
+ private function __construct()
29
+ {
30
+ }
31
+
32
+ /**
33
+ * Escapes a string to be used as a shell argument.
34
+ *
35
+ * @param string $argument The argument that will be escaped
36
+ *
37
+ * @return string The escaped argument
38
+ */
39
+ public static function escapeArgument($argument)
40
+ {
41
+ //Fix for PHP bug #43784 escapeshellarg removes % from given string
42
+ //Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
43
+ //@see https://bugs.php.net/bug.php?id=43784
44
+ //@see https://bugs.php.net/bug.php?id=49446
45
+ if ('\\' === DIRECTORY_SEPARATOR) {
46
+ if ('' === $argument) {
47
+ return escapeshellarg($argument);
48
+ }
49
+
50
+ $escapedArgument = '';
51
+ $quote = false;
52
+ foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
53
+ if ('"' === $part) {
54
+ $escapedArgument .= '\\"';
55
+ } elseif (self::isSurroundedBy($part, '%')) {
56
+ // Avoid environment variable expansion
57
+ $escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
58
+ } else {
59
+ // escape trailing backslash
60
+ if ('\\' === substr($part, -1)) {
61
+ $part .= '\\';
62
+ }
63
+ $quote = true;
64
+ $escapedArgument .= $part;
65
+ }
66
+ }
67
+ if ($quote) {
68
+ $escapedArgument = '"'.$escapedArgument.'"';
69
+ }
70
+
71
+ return $escapedArgument;
72
+ }
73
+
74
+ return escapeshellarg($argument);
75
+ }
76
+
77
+ /**
78
+ * Validates and normalizes a Process input.
79
+ *
80
+ * @param string $caller The name of method call that validates the input
81
+ * @param mixed $input The input to validate
82
+ *
83
+ * @return string The validated input
84
+ *
85
+ * @throws InvalidArgumentException In case the input is not valid
86
+ *
87
+ * Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.
88
+ */
89
+ public static function validateInput($caller, $input)
90
+ {
91
+ if (null !== $input) {
92
+ if (is_resource($input)) {
93
+ return $input;
94
+ }
95
+ if (is_scalar($input)) {
96
+ return (string) $input;
97
+ }
98
+ // deprecated as of Symfony 2.5, to be removed in 3.0
99
+ if (is_object($input) && method_exists($input, '__toString')) {
100
+ @trigger_error('Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
101
+
102
+ return (string) $input;
103
+ }
104
+
105
+ throw new InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller));
106
+ }
107
+
108
+ return $input;
109
+ }
110
+
111
+ private static function isSurroundedBy($arg, $char)
112
+ {
113
+ return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
114
+ }
115
+ }
vendor/symfony/process/Tests/ExecutableFinderTest.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Tests;
13
+
14
+ use Symfony\Component\Process\ExecutableFinder;
15
+
16
+ /**
17
+ * @author Chris Smith <chris@cs278.org>
18
+ */
19
+ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase
20
+ {
21
+ private $path;
22
+
23
+ protected function tearDown()
24
+ {
25
+ if ($this->path) {
26
+ // Restore path if it was changed.
27
+ putenv('PATH='.$this->path);
28
+ }
29
+ }
30
+
31
+ private function setPath($path)
32
+ {
33
+ $this->path = getenv('PATH');
34
+ putenv('PATH='.$path);
35
+ }
36
+
37
+ /**
38
+ * @requires PHP 5.4
39
+ */
40
+ public function testFind()
41
+ {
42
+ if (ini_get('open_basedir')) {
43
+ $this->markTestSkipped('Cannot test when open_basedir is set');
44
+ }
45
+
46
+ $this->setPath(dirname(PHP_BINARY));
47
+
48
+ $finder = new ExecutableFinder();
49
+ $result = $finder->find($this->getPhpBinaryName());
50
+
51
+ $this->assertSamePath(PHP_BINARY, $result);
52
+ }
53
+
54
+ public function testFindWithDefault()
55
+ {
56
+ if (ini_get('open_basedir')) {
57
+ $this->markTestSkipped('Cannot test when open_basedir is set');
58
+ }
59
+
60
+ $expected = 'defaultValue';
61
+
62
+ $this->setPath('');
63
+
64
+ $finder = new ExecutableFinder();
65
+ $result = $finder->find('foo', $expected);
66
+
67
+ $this->assertEquals($expected, $result);
68
+ }
69
+
70
+ /**
71
+ * @requires PHP 5.4
72
+ */
73
+ public function testFindWithExtraDirs()
74
+ {
75
+ if (ini_get('open_basedir')) {
76
+ $this->markTestSkipped('Cannot test when open_basedir is set');
77
+ }
78
+
79
+ $this->setPath('');
80
+
81
+ $extraDirs = array(dirname(PHP_BINARY));
82
+
83
+ $finder = new ExecutableFinder();
84
+ $result = $finder->find($this->getPhpBinaryName(), null, $extraDirs);
85
+
86
+ $this->assertSamePath(PHP_BINARY, $result);
87
+ }
88
+
89
+ /**
90
+ * @requires PHP 5.4
91
+ */
92
+ public function testFindWithOpenBaseDir()
93
+ {
94
+ if ('\\' === DIRECTORY_SEPARATOR) {
95
+ $this->markTestSkipped('Cannot run test on windows');
96
+ }
97
+
98
+ if (ini_get('open_basedir')) {
99
+ $this->markTestSkipped('Cannot test when open_basedir is set');
100
+ }
101
+
102
+ $this->iniSet('open_basedir', dirname(PHP_BINARY).(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : ''));
103
+
104
+ $finder = new ExecutableFinder();
105
+ $result = $finder->find($this->getPhpBinaryName());
106
+
107
+ $this->assertSamePath(PHP_BINARY, $result);
108
+ }
109
+
110
+ /**
111
+ * @requires PHP 5.4
112
+ */
113
+ public function testFindProcessInOpenBasedir()
114
+ {
115
+ if (ini_get('open_basedir')) {
116
+ $this->markTestSkipped('Cannot test when open_basedir is set');
117
+ }
118
+ if ('\\' === DIRECTORY_SEPARATOR) {
119
+ $this->markTestSkipped('Cannot run test on windows');
120
+ }
121
+
122
+ $this->setPath('');
123
+ $this->iniSet('open_basedir', PHP_BINARY.(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : ''));
124
+
125
+ $finder = new ExecutableFinder();
126
+ $result = $finder->find($this->getPhpBinaryName(), false);
127
+
128
+ $this->assertSamePath(PHP_BINARY, $result);
129
+ }
130
+
131
+ private function assertSamePath($expected, $tested)
132
+ {
133
+ if ('\\' === DIRECTORY_SEPARATOR) {
134
+ $this->assertEquals(strtolower($expected), strtolower($tested));
135
+ } else {
136
+ $this->assertEquals($expected, $tested);
137
+ }
138
+ }
139
+
140
+ private function getPhpBinaryName()
141
+ {
142
+ return basename(PHP_BINARY, '\\' === DIRECTORY_SEPARATOR ? '.exe' : '');
143
+ }
144
+ }
vendor/symfony/process/Tests/NonStopableProcess.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ /**
13
+ * Runs a PHP script that can be stopped only with a SIGKILL (9) signal for 3 seconds.
14
+ *
15
+ * @args duration Run this script with a custom duration
16
+ *
17
+ * @example `php NonStopableProcess.php 42` will run the script for 42 seconds
18
+ */
19
+ function handleSignal($signal)
20
+ {
21
+ switch ($signal) {
22
+ case SIGTERM:
23
+ $name = 'SIGTERM';
24
+ break;
25
+ case SIGINT:
26
+ $name = 'SIGINT';
27
+ break;
28
+ default:
29
+ $name = $signal.' (unknown)';
30
+ break;
31
+ }
32
+
33
+ echo "signal $name\n";
34
+ }
35
+
36
+ pcntl_signal(SIGTERM, 'handleSignal');
37
+ pcntl_signal(SIGINT, 'handleSignal');
38
+
39
+ echo 'received ';
40
+
41
+ $duration = isset($argv[1]) ? (int) $argv[1] : 3;
42
+ $start = microtime(true);
43
+
44
+ while ($duration > (microtime(true) - $start)) {
45
+ usleep(10000);
46
+ pcntl_signal_dispatch();
47
+ }
vendor/symfony/process/Tests/PhpExecutableFinderTest.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Tests;
13
+
14
+ use Symfony\Component\Process\PhpExecutableFinder;
15
+
16
+ /**
17
+ * @author Robert Schönthal <seroscho@googlemail.com>
18
+ */
19
+ class PhpExecutableFinderTest extends \PHPUnit_Framework_TestCase
20
+ {
21
+ /**
22
+ * tests find() with the env var PHP_PATH.
23
+ */
24
+ public function testFindWithPhpPath()
25
+ {
26
+ if (defined('PHP_BINARY')) {
27
+ $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
28
+ }
29
+
30
+ $f = new PhpExecutableFinder();
31
+
32
+ $current = $f->find();
33
+
34
+ //not executable PHP_PATH
35
+ putenv('PHP_PATH=/not/executable/php');
36
+ $this->assertFalse($f->find(), '::find() returns false for not executable PHP');
37
+ $this->assertFalse($f->find(false), '::find() returns false for not executable PHP');
38
+
39
+ //executable PHP_PATH
40
+ putenv('PHP_PATH='.$current);
41
+ $this->assertEquals($f->find(), $current, '::find() returns the executable PHP');
42
+ $this->assertEquals($f->find(false), $current, '::find() returns the executable PHP');
43
+ }
44
+
45
+ /**
46
+ * tests find() with the constant PHP_BINARY.
47
+ *
48
+ * @requires PHP 5.4
49
+ */
50
+ public function testFind()
51
+ {
52
+ if (defined('HHVM_VERSION')) {
53
+ $this->markTestSkipped('Should not be executed in HHVM context.');
54
+ }
55
+
56
+ $f = new PhpExecutableFinder();
57
+
58
+ $current = PHP_BINARY;
59
+ $args = 'phpdbg' === PHP_SAPI ? ' -qrr' : '';
60
+
61
+ $this->assertEquals($current.$args, $f->find(), '::find() returns the executable PHP');
62
+ $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
63
+ }
64
+
65
+ /**
66
+ * tests find() with the env var / constant PHP_BINARY with HHVM.
67
+ */
68
+ public function testFindWithHHVM()
69
+ {
70
+ if (!defined('HHVM_VERSION')) {
71
+ $this->markTestSkipped('Should be executed in HHVM context.');
72
+ }
73
+
74
+ $f = new PhpExecutableFinder();
75
+
76
+ $current = getenv('PHP_BINARY') ?: PHP_BINARY;
77
+
78
+ $this->assertEquals($current.' --php', $f->find(), '::find() returns the executable PHP');
79
+ $this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
80
+ }
81
+
82
+ /**
83
+ * tests find() with the env var PHP_PATH.
84
+ */
85
+ public function testFindArguments()
86
+ {
87
+ $f = new PhpExecutableFinder();
88
+
89
+ if (defined('HHVM_VERSION')) {
90
+ $this->assertEquals($f->findArguments(), array('--php'), '::findArguments() returns HHVM arguments');
91
+ } elseif ('phpdbg' === PHP_SAPI) {
92
+ $this->assertEquals($f->findArguments(), array('-qrr'), '::findArguments() returns phpdbg arguments');
93
+ } else {
94
+ $this->assertEquals($f->findArguments(), array(), '::findArguments() returns no arguments');
95
+ }
96
+ }
97
+
98
+ /**
99
+ * tests find() with default executable.
100
+ */
101
+ public function testFindWithSuffix()
102
+ {
103
+ if (defined('PHP_BINARY')) {
104
+ $this->markTestSkipped('The PHP binary is easily available as of PHP 5.4');
105
+ }
106
+
107
+ putenv('PHP_PATH=');
108
+ putenv('PHP_PEAR_PHP_BIN=');
109
+ $f = new PhpExecutableFinder();
110
+
111
+ $current = $f->find();
112
+
113
+ //TODO maybe php executable is custom or even Windows
114
+ if ('\\' === DIRECTORY_SEPARATOR) {
115
+ $this->assertTrue(is_executable($current));
116
+ $this->assertTrue((bool) preg_match('/'.addslashes(DIRECTORY_SEPARATOR).'php\.(exe|bat|cmd|com)$/i', $current), '::find() returns the executable PHP with suffixes');
117
+ }
118
+ }
119
+ }
vendor/symfony/process/Tests/PhpProcessTest.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Tests;
13
+
14
+ use Symfony\Component\Process\PhpExecutableFinder;
15
+ use Symfony\Component\Process\PhpProcess;
16
+
17
+ class PhpProcessTest extends \PHPUnit_Framework_TestCase
18
+ {
19
+ public function testNonBlockingWorks()
20
+ {
21
+ $expected = 'hello world!';
22
+ $process = new PhpProcess(<<<PHP
23
+ <?php echo '$expected';
24
+ PHP
25
+ );
26
+ $process->start();
27
+ $process->wait();
28
+ $this->assertEquals($expected, $process->getOutput());
29
+ }
30
+
31
+ public function testCommandLine()
32
+ {
33
+ $process = new PhpProcess(<<<'PHP'
34
+ <?php echo 'foobar';
35
+ PHP
36
+ );
37
+
38
+ $commandLine = $process->getCommandLine();
39
+
40
+ $f = new PhpExecutableFinder();
41
+ $this->assertContains($f->find(), $commandLine, '::getCommandLine() returns the command line of PHP before start');
42
+
43
+ $process->start();
44
+ $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after start');
45
+
46
+ $process->wait();
47
+ $this->assertContains($commandLine, $process->getCommandLine(), '::getCommandLine() returns the command line of PHP after wait');
48
+ }
49
+ }
vendor/symfony/process/Tests/PipeStdinInStdoutStdErrStreamSelect.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ define('ERR_SELECT_FAILED', 1);
13
+ define('ERR_TIMEOUT', 2);
14
+ define('ERR_READ_FAILED', 3);
15
+ define('ERR_WRITE_FAILED', 4);
16
+
17
+ $read = array(STDIN);
18
+ $write = array(STDOUT, STDERR);
19
+
20
+ stream_set_blocking(STDIN, 0);
21
+ stream_set_blocking(STDOUT, 0);
22
+ stream_set_blocking(STDERR, 0);
23
+
24
+ $out = $err = '';
25
+ while ($read || $write) {
26
+ $r = $read;
27
+ $w = $write;
28
+ $e = null;
29
+ $n = stream_select($r, $w, $e, 5);
30
+
31
+ if (false === $n) {
32
+ die(ERR_SELECT_FAILED);
33
+ } elseif ($n < 1) {
34
+ die(ERR_TIMEOUT);
35
+ }
36
+
37
+ if (in_array(STDOUT, $w) && strlen($out) > 0) {
38
+ $written = fwrite(STDOUT, (binary) $out, 32768);
39
+ if (false === $written) {
40
+ die(ERR_WRITE_FAILED);
41
+ }
42
+ $out = (binary) substr($out, $written);
43
+ }
44
+ if (null === $read && '' === $out) {
45
+ $write = array_diff($write, array(STDOUT));
46
+ }
47
+
48
+ if (in_array(STDERR, $w) && strlen($err) > 0) {
49
+ $written = fwrite(STDERR, (binary) $err, 32768);
50
+ if (false === $written) {
51
+ die(ERR_WRITE_FAILED);
52
+ }
53
+ $err = (binary) substr($err, $written);
54
+ }
55
+ if (null === $read && '' === $err) {
56
+ $write = array_diff($write, array(STDERR));
57
+ }
58
+
59
+ if ($r) {
60
+ $str = fread(STDIN, 32768);
61
+ if (false !== $str) {
62
+ $out .= $str;
63
+ $err .= $str;
64
+ }
65
+ if (false === $str || feof(STDIN)) {
66
+ $read = null;
67
+ if (!feof(STDIN)) {
68
+ die(ERR_READ_FAILED);
69
+ }
70
+ }
71
+ }
72
+ }
vendor/symfony/process/Tests/ProcessBuilderTest.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Tests;
13
+
14
+ use Symfony\Component\Process\ProcessBuilder;
15
+
16
+ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
17
+ {
18
+ public function testInheritEnvironmentVars()
19
+ {
20
+ $_ENV['MY_VAR_1'] = 'foo';
21
+
22
+ $proc = ProcessBuilder::create()
23
+ ->add('foo')
24
+ ->getProcess();
25
+
26
+ unset($_ENV['MY_VAR_1']);
27
+
28
+ $env = $proc->getEnv();
29
+ $this->assertArrayHasKey('MY_VAR_1', $env);
30
+ $this->assertEquals('foo', $env['MY_VAR_1']);
31
+ }
32
+
33
+ public function testAddEnvironmentVariables()
34
+ {
35
+ $pb = new ProcessBuilder();
36
+ $env = array(
37
+ 'foo' => 'bar',
38
+ 'foo2' => 'bar2',
39
+ );
40
+ $proc = $pb
41
+ ->add('command')
42
+ ->setEnv('foo', 'bar2')
43
+ ->addEnvironmentVariables($env)
44
+ ->inheritEnvironmentVariables(false)
45
+ ->getProcess()
46
+ ;
47
+
48
+ $this->assertSame($env, $proc->getEnv());
49
+ }
50
+
51
+ public function testProcessShouldInheritAndOverrideEnvironmentVars()
52
+ {
53
+ $_ENV['MY_VAR_1'] = 'foo';
54
+
55
+ $proc = ProcessBuilder::create()
56
+ ->setEnv('MY_VAR_1', 'bar')
57
+ ->add('foo')
58
+ ->getProcess();
59
+
60
+ unset($_ENV['MY_VAR_1']);
61
+
62
+ $env = $proc->getEnv();
63
+ $this->assertArrayHasKey('MY_VAR_1', $env);
64
+ $this->assertEquals('bar', $env['MY_VAR_1']);
65
+ }
66
+
67
+ /**
68
+ * @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
69
+ */
70
+ public function testNegativeTimeoutFromSetter()
71
+ {
72
+ $pb = new ProcessBuilder();
73
+ $pb->setTimeout(-1);
74
+ }
75
+
76
+ public function testNullTimeout()
77
+ {
78
+ $pb = new ProcessBuilder();
79
+ $pb->setTimeout(10);
80
+ $pb->setTimeout(null);
81
+
82
+ $r = new \ReflectionObject($pb);
83
+ $p = $r->getProperty('timeout');
84
+ $p->setAccessible(true);
85
+
86
+ $this->assertNull($p->getValue($pb));
87
+ }
88
+
89
+ public function testShouldSetArguments()
90
+ {
91
+ $pb = new ProcessBuilder(array('initial'));
92
+ $pb->setArguments(array('second'));
93
+
94
+ $proc = $pb->getProcess();
95
+
96
+ $this->assertContains('second', $proc->getCommandLine());
97
+ }
98
+
99
+ public function testPrefixIsPrependedToAllGeneratedProcess()
100
+ {
101
+ $pb = new ProcessBuilder();
102
+ $pb->setPrefix('/usr/bin/php');
103
+
104
+ $proc = $pb->setArguments(array('-v'))->getProcess();
105
+ if ('\\' === DIRECTORY_SEPARATOR) {
106
+ $this->assertEquals('"/usr/bin/php" "-v"', $proc->getCommandLine());
107
+ } else {
108
+ $this->assertEquals("'/usr/bin/php' '-v'", $proc->getCommandLine());
109
+ }
110
+
111
+ $proc = $pb->setArguments(array('-i'))->getProcess();
112
+ if ('\\' === DIRECTORY_SEPARATOR) {
113
+ $this->assertEquals('"/usr/bin/php" "-i"', $proc->getCommandLine());
114
+ } else {
115
+ $this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
116
+ }
117
+ }
118
+
119
+ public function testArrayPrefixesArePrependedToAllGeneratedProcess()
120
+ {
121
+ $pb = new ProcessBuilder();
122
+ $pb->setPrefix(array('/usr/bin/php', 'composer.phar'));
123
+
124
+ $proc = $pb->setArguments(array('-v'))->getProcess();
125
+ if ('\\' === DIRECTORY_SEPARATOR) {
126
+ $this->assertEquals('"/usr/bin/php" "composer.phar" "-v"', $proc->getCommandLine());
127
+ } else {
128
+ $this->assertEquals("'/usr/bin/php' 'composer.phar' '-v'", $proc->getCommandLine());
129
+ }
130
+
131
+ $proc = $pb->setArguments(array('-i'))->getProcess();
132
+ if ('\\' === DIRECTORY_SEPARATOR) {
133
+ $this->assertEquals('"/usr/bin/php" "composer.phar" "-i"', $proc->getCommandLine());
134
+ } else {
135
+ $this->assertEquals("'/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
136
+ }
137
+ }
138
+
139
+ public function testShouldEscapeArguments()
140
+ {
141
+ $pb = new ProcessBuilder(array('%path%', 'foo " bar', '%baz%baz'));
142
+ $proc = $pb->getProcess();
143
+
144
+ if ('\\' === DIRECTORY_SEPARATOR) {
145
+ $this->assertSame('^%"path"^% "foo \\" bar" "%baz%baz"', $proc->getCommandLine());
146
+ } else {
147
+ $this->assertSame("'%path%' 'foo \" bar' '%baz%baz'", $proc->getCommandLine());
148
+ }
149
+ }
150
+
151
+ public function testShouldEscapeArgumentsAndPrefix()
152
+ {
153
+ $pb = new ProcessBuilder(array('arg'));
154
+ $pb->setPrefix('%prefix%');
155
+ $proc = $pb->getProcess();
156
+
157
+ if ('\\' === DIRECTORY_SEPARATOR) {
158
+ $this->assertSame('^%"prefix"^% "arg"', $proc->getCommandLine());
159
+ } else {
160
+ $this->assertSame("'%prefix%' 'arg'", $proc->getCommandLine());
161
+ }
162
+ }
163
+
164
+ /**
165
+ * @expectedException \Symfony\Component\Process\Exception\LogicException
166
+ */
167
+ public function testShouldThrowALogicExceptionIfNoPrefixAndNoArgument()
168
+ {
169
+ ProcessBuilder::create()->getProcess();
170
+ }
171
+
172
+ public function testShouldNotThrowALogicExceptionIfNoArgument()
173
+ {
174
+ $process = ProcessBuilder::create()
175
+ ->setPrefix('/usr/bin/php')
176
+ ->getProcess();
177
+
178
+ if ('\\' === DIRECTORY_SEPARATOR) {
179
+ $this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
180
+ } else {
181
+ $this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
182
+ }
183
+ }
184
+
185
+ public function testShouldNotThrowALogicExceptionIfNoPrefix()
186
+ {
187
+ $process = ProcessBuilder::create(array('/usr/bin/php'))
188
+ ->getProcess();
189
+
190
+ if ('\\' === DIRECTORY_SEPARATOR) {
191
+ $this->assertEquals('"/usr/bin/php"', $process->getCommandLine());
192
+ } else {
193
+ $this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
194
+ }
195
+ }
196
+
197
+ public function testShouldReturnProcessWithDisabledOutput()
198
+ {
199
+ $process = ProcessBuilder::create(array('/usr/bin/php'))
200
+ ->disableOutput()
201
+ ->getProcess();
202
+
203
+ $this->assertTrue($process->isOutputDisabled());
204
+ }
205
+
206
+ public function testShouldReturnProcessWithEnabledOutput()
207
+ {
208
+ $process = ProcessBuilder::create(array('/usr/bin/php'))
209
+ ->disableOutput()
210
+ ->enableOutput()
211
+ ->getProcess();
212
+
213
+ $this->assertFalse($process->isOutputDisabled());
214
+ }
215
+
216
+ /**
217
+ * @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
218
+ * @expectedExceptionMessage Symfony\Component\Process\ProcessBuilder::setInput only accepts strings or stream resources.
219
+ */
220
+ public function testInvalidInput()
221
+ {
222
+ $builder = ProcessBuilder::create();
223
+ $builder->setInput(array());
224
+ }
225
+ }
vendor/symfony/process/Tests/ProcessFailedExceptionTest.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Tests;
13
+
14
+ use Symfony\Component\Process\Exception\ProcessFailedException;
15
+
16
+ /**
17
+ * @author Sebastian Marek <proofek@gmail.com>
18
+ */
19
+ class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
20
+ {
21
+ /**
22
+ * tests ProcessFailedException throws exception if the process was successful.
23
+ */
24
+ public function testProcessFailedExceptionThrowsException()
25
+ {
26
+ $process = $this->getMock(
27
+ 'Symfony\Component\Process\Process',
28
+ array('isSuccessful'),
29
+ array('php')
30
+ );
31
+ $process->expects($this->once())
32
+ ->method('isSuccessful')
33
+ ->will($this->returnValue(true));
34
+
35
+ $this->setExpectedException(
36
+ '\InvalidArgumentException',
37
+ 'Expected a failed process, but the given process was successful.'
38
+ );
39
+
40
+ new ProcessFailedException($process);
41
+ }
42
+
43
+ /**
44
+ * tests ProcessFailedException uses information from process output
45
+ * to generate exception message.
46
+ */
47
+ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput()
48
+ {
49
+ $cmd = 'php';
50
+ $exitCode = 1;
51
+ $exitText = 'General error';
52
+ $output = 'Command output';
53
+ $errorOutput = 'FATAL: Unexpected error';
54
+ $workingDirectory = getcwd();
55
+
56
+ $process = $this->getMock(
57
+ 'Symfony\Component\Process\Process',
58
+ array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'),
59
+ array($cmd)
60
+ );
61
+ $process->expects($this->once())
62
+ ->method('isSuccessful')
63
+ ->will($this->returnValue(false));
64
+
65
+ $process->expects($this->once())
66
+ ->method('getOutput')
67
+ ->will($this->returnValue($output));
68
+
69
+ $process->expects($this->once())
70
+ ->method('getErrorOutput')
71
+ ->will($this->returnValue($errorOutput));
72
+
73
+ $process->expects($this->once())
74
+ ->method('getExitCode')
75
+ ->will($this->returnValue($exitCode));
76
+
77
+ $process->expects($this->once())
78
+ ->method('getExitCodeText')
79
+ ->will($this->returnValue($exitText));
80
+
81
+ $process->expects($this->once())
82
+ ->method('isOutputDisabled')
83
+ ->will($this->returnValue(false));
84
+
85
+ $process->expects($this->once())
86
+ ->method('getWorkingDirectory')
87
+ ->will($this->returnValue($workingDirectory));
88
+
89
+ $exception = new ProcessFailedException($process);
90
+
91
+ $this->assertEquals(
92
+ "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
93
+ $exception->getMessage()
94
+ );
95
+ }
96
+
97
+ /**
98
+ * Tests that ProcessFailedException does not extract information from
99
+ * process output if it was previously disabled.
100
+ */
101
+ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
102
+ {
103
+ $cmd = 'php';
104
+ $exitCode = 1;
105
+ $exitText = 'General error';
106
+ $workingDirectory = getcwd();
107
+
108
+ $process = $this->getMock(
109
+ 'Symfony\Component\Process\Process',
110
+ array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'),
111
+ array($cmd)
112
+ );
113
+ $process->expects($this->once())
114
+ ->method('isSuccessful')
115
+ ->will($this->returnValue(false));
116
+
117
+ $process->expects($this->never())
118
+ ->method('getOutput');
119
+
120
+ $process->expects($this->never())
121
+ ->method('getErrorOutput');
122
+
123
+ $process->expects($this->once())
124
+ ->method('getExitCode')
125
+ ->will($this->returnValue($exitCode));
126
+
127
+ $process->expects($this->once())
128
+ ->method('getExitCodeText')
129
+ ->will($this->returnValue($exitText));
130
+
131
+ $process->expects($this->once())
132
+ ->method('isOutputDisabled')
133
+ ->will($this->returnValue(true));
134
+
135
+ $process->expects($this->once())
136
+ ->method('getWorkingDirectory')
137
+ ->will($this->returnValue($workingDirectory));
138
+
139
+ $exception = new ProcessFailedException($process);
140
+
141
+ $this->assertEquals(
142
+ "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}",
143
+ $exception->getMessage()
144
+ );
145
+ }
146
+ }
vendor/symfony/process/Tests/ProcessTest.php ADDED
@@ -0,0 +1,1244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Tests;
13
+
14
+ use Symfony\Component\Process\Exception\LogicException;
15
+ use Symfony\Component\Process\Exception\ProcessTimedOutException;
16
+ use Symfony\Component\Process\Exception\RuntimeException;
17
+ use Symfony\Component\Process\PhpExecutableFinder;
18
+ use Symfony\Component\Process\Pipes\PipesInterface;
19
+ use Symfony\Component\Process\Process;
20
+
21
+ /**
22
+ * @author Robert Schönthal <seroscho@googlemail.com>
23
+ */
24
+ class ProcessTest extends \PHPUnit_Framework_TestCase
25
+ {
26
+ private static $phpBin;
27
+ private static $process;
28
+ private static $sigchild;
29
+ private static $notEnhancedSigchild = false;
30
+
31
+ public static function setUpBeforeClass()
32
+ {
33
+ $phpBin = new PhpExecutableFinder();
34
+ self::$phpBin = 'phpdbg' === PHP_SAPI ? 'php' : $phpBin->find();
35
+ if ('\\' !== DIRECTORY_SEPARATOR) {
36
+ // exec is mandatory to deal with sending a signal to the process
37
+ // see https://github.com/symfony/symfony/issues/5030 about prepending
38
+ // command with exec
39
+ self::$phpBin = 'exec '.self::$phpBin;
40
+ }
41
+
42
+ ob_start();
43
+ phpinfo(INFO_GENERAL);
44
+ self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
45
+ }
46
+
47
+ protected function tearDown()
48
+ {
49
+ if (self::$process) {
50
+ self::$process->stop(0);
51
+ self::$process = null;
52
+ }
53
+ }
54
+
55
+ public function testThatProcessDoesNotThrowWarningDuringRun()
56
+ {
57
+ @trigger_error('Test Error', E_USER_NOTICE);
58
+ $process = $this->getProcess(self::$phpBin." -r 'sleep(3)'");
59
+ $process->run();
60
+ $actualError = error_get_last();
61
+ $this->assertEquals('Test Error', $actualError['message']);
62
+ $this->assertEquals(E_USER_NOTICE, $actualError['type']);
63
+ }
64
+
65
+ /**
66
+ * @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
67
+ */
68
+ public function testNegativeTimeoutFromConstructor()
69
+ {
70
+ $this->getProcess('', null, null, null, -1);
71
+ }
72
+
73
+ /**
74
+ * @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
75
+ */
76
+ public function testNegativeTimeoutFromSetter()
77
+ {
78
+ $p = $this->getProcess('');
79
+ $p->setTimeout(-1);
80
+ }
81
+
82
+ public function testFloatAndNullTimeout()
83
+ {
84
+ $p = $this->getProcess('');
85
+
86
+ $p->setTimeout(10);
87
+ $this->assertSame(10.0, $p->getTimeout());
88
+
89
+ $p->setTimeout(null);
90
+ $this->assertNull($p->getTimeout());
91
+
92
+ $p->setTimeout(0.0);
93
+ $this->assertNull($p->getTimeout());
94
+ }
95
+
96
+ /**
97
+ * @requires extension pcntl
98
+ */
99
+ public function testStopWithTimeoutIsActuallyWorking()
100
+ {
101
+ $p = $this->getProcess(self::$phpBin.' '.__DIR__.'/NonStopableProcess.php 30');
102
+ $p->start();
103
+
104
+ while (false === strpos($p->getOutput(), 'received')) {
105
+ usleep(1000);
106
+ }
107
+ $start = microtime(true);
108
+ $p->stop(0.1);
109
+
110
+ $p->wait();
111
+
112
+ $this->assertLessThan(15, microtime(true) - $start);
113
+ }
114
+
115
+ public function testAllOutputIsActuallyReadOnTermination()
116
+ {
117
+ // this code will result in a maximum of 2 reads of 8192 bytes by calling
118
+ // start() and isRunning(). by the time getOutput() is called the process
119
+ // has terminated so the internal pipes array is already empty. normally
120
+ // the call to start() will not read any data as the process will not have
121
+ // generated output, but this is non-deterministic so we must count it as
122
+ // a possibility. therefore we need 2 * PipesInterface::CHUNK_SIZE plus
123
+ // another byte which will never be read.
124
+ $expectedOutputSize = PipesInterface::CHUNK_SIZE * 2 + 2;
125
+
126
+ $code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize);
127
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
128
+
129
+ $p->start();
130
+
131
+ // Don't call Process::run nor Process::wait to avoid any read of pipes
132
+ $h = new \ReflectionProperty($p, 'process');
133
+ $h->setAccessible(true);
134
+ $h = $h->getValue($p);
135
+ $s = @proc_get_status($h);
136
+
137
+ while (!empty($s['running'])) {
138
+ usleep(1000);
139
+ $s = proc_get_status($h);
140
+ }
141
+
142
+ $o = $p->getOutput();
143
+
144
+ $this->assertEquals($expectedOutputSize, strlen($o));
145
+ }
146
+
147
+ public function testCallbacksAreExecutedWithStart()
148
+ {
149
+ $process = $this->getProcess('echo foo');
150
+ $process->start(function ($type, $buffer) use (&$data) {
151
+ $data .= $buffer;
152
+ });
153
+
154
+ $process->wait();
155
+
156
+ $this->assertSame('foo'.PHP_EOL, $data);
157
+ }
158
+
159
+ /**
160
+ * tests results from sub processes.
161
+ *
162
+ * @dataProvider responsesCodeProvider
163
+ */
164
+ public function testProcessResponses($expected, $getter, $code)
165
+ {
166
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
167
+ $p->run();
168
+
169
+ $this->assertSame($expected, $p->$getter());
170
+ }
171
+
172
+ /**
173
+ * tests results from sub processes.
174
+ *
175
+ * @dataProvider pipesCodeProvider
176
+ */
177
+ public function testProcessPipes($code, $size)
178
+ {
179
+ $expected = str_repeat(str_repeat('*', 1024), $size).'!';
180
+ $expectedLength = (1024 * $size) + 1;
181
+
182
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
183
+ $p->setInput($expected);
184
+ $p->run();
185
+
186
+ $this->assertEquals($expectedLength, strlen($p->getOutput()));
187
+ $this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
188
+ }
189
+
190
+ /**
191
+ * @dataProvider pipesCodeProvider
192
+ */
193
+ public function testSetStreamAsInput($code, $size)
194
+ {
195
+ if ('\\' === DIRECTORY_SEPARATOR) {
196
+ $this->markTestIncomplete('This test fails with a timeout on Windows, can someone investigate please?');
197
+ }
198
+ $expected = str_repeat(str_repeat('*', 1024), $size).'!';
199
+ $expectedLength = (1024 * $size) + 1;
200
+
201
+ $stream = fopen('php://temporary', 'w+');
202
+ fwrite($stream, $expected);
203
+ rewind($stream);
204
+
205
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg($code)));
206
+ $p->setInput($stream);
207
+ $p->run();
208
+
209
+ fclose($stream);
210
+
211
+ $this->assertEquals($expectedLength, strlen($p->getOutput()));
212
+ $this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
213
+ }
214
+
215
+ /**
216
+ * @expectedException \Symfony\Component\Process\Exception\LogicException
217
+ * @expectedExceptionMessage Input can not be set while the process is running.
218
+ */
219
+ public function testSetInputWhileRunningThrowsAnException()
220
+ {
221
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(30);"');
222
+ $process->start();
223
+ try {
224
+ $process->setInput('foobar');
225
+ $process->stop();
226
+ $this->fail('A LogicException should have been raised.');
227
+ } catch (LogicException $e) {
228
+ }
229
+ $process->stop();
230
+
231
+ throw $e;
232
+ }
233
+
234
+ /**
235
+ * @dataProvider provideInvalidInputValues
236
+ * @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
237
+ * @expectedExceptionMessage Symfony\Component\Process\Process::setInput only accepts strings or stream resources.
238
+ */
239
+ public function testInvalidInput($value)
240
+ {
241
+ $process = $this->getProcess('foo');
242
+ $process->setInput($value);
243
+ }
244
+
245
+ public function provideInvalidInputValues()
246
+ {
247
+ return array(
248
+ array(array()),
249
+ array(new NonStringifiable()),
250
+ );
251
+ }
252
+
253
+ /**
254
+ * @dataProvider provideInputValues
255
+ */
256
+ public function testValidInput($expected, $value)
257
+ {
258
+ $process = $this->getProcess('foo');
259
+ $process->setInput($value);
260
+ $this->assertSame($expected, $process->getInput());
261
+ }
262
+
263
+ public function provideInputValues()
264
+ {
265
+ return array(
266
+ array(null, null),
267
+ array('24.5', 24.5),
268
+ array('input data', 'input data'),
269
+ );
270
+ }
271
+
272
+ /**
273
+ * @dataProvider provideLegacyInputValues
274
+ * @group legacy
275
+ */
276
+ public function testLegacyValidInput($expected, $value)
277
+ {
278
+ $process = $this->getProcess(self::$phpBin.' -v');
279
+ $process->setInput($value);
280
+ $this->assertSame($expected, $process->getInput());
281
+ }
282
+
283
+ public function provideLegacyInputValues()
284
+ {
285
+ return array(
286
+ array('stringifiable', new Stringifiable()),
287
+ );
288
+ }
289
+
290
+ public function chainedCommandsOutputProvider()
291
+ {
292
+ if ('\\' === DIRECTORY_SEPARATOR) {
293
+ return array(
294
+ array("2 \r\n2\r\n", '&&', '2'),
295
+ );
296
+ }
297
+
298
+ return array(
299
+ array("1\n1\n", ';', '1'),
300
+ array("2\n2\n", '&&', '2'),
301
+ );
302
+ }
303
+
304
+ /**
305
+ * @dataProvider chainedCommandsOutputProvider
306
+ */
307
+ public function testChainedCommandsOutput($expected, $operator, $input)
308
+ {
309
+ $process = $this->getProcess(sprintf('echo %s %s echo %s', $input, $operator, $input));
310
+ $process->run();
311
+ $this->assertEquals($expected, $process->getOutput());
312
+ }
313
+
314
+ public function testCallbackIsExecutedForOutput()
315
+ {
316
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('echo \'foo\';')));
317
+
318
+ $called = false;
319
+ $p->run(function ($type, $buffer) use (&$called) {
320
+ $called = $buffer === 'foo';
321
+ });
322
+
323
+ $this->assertTrue($called, 'The callback should be executed with the output');
324
+ }
325
+
326
+ public function testGetErrorOutput()
327
+ {
328
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
329
+
330
+ $p->run();
331
+ $this->assertEquals(3, preg_match_all('/ERROR/', $p->getErrorOutput(), $matches));
332
+ }
333
+
334
+ public function testFlushErrorOutput()
335
+ {
336
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
337
+
338
+ $p->run();
339
+ $p->clearErrorOutput();
340
+ $this->assertEmpty($p->getErrorOutput());
341
+ }
342
+
343
+ /**
344
+ * @dataProvider provideIncrementalOutput
345
+ */
346
+ public function testIncrementalOutput($getOutput, $getIncrementalOutput, $uri)
347
+ {
348
+ $lock = tempnam(sys_get_temp_dir(), __FUNCTION__);
349
+
350
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('file_put_contents($s = \''.$uri.'\', \'foo\'); flock(fopen('.var_export($lock, true).', \'r\'), LOCK_EX); file_put_contents($s, \'bar\');')));
351
+
352
+ $h = fopen($lock, 'w');
353
+ flock($h, LOCK_EX);
354
+
355
+ $p->start();
356
+
357
+ foreach (array('foo', 'bar') as $s) {
358
+ while (false === strpos($p->$getOutput(), $s)) {
359
+ usleep(1000);
360
+ }
361
+
362
+ $this->assertSame($s, $p->$getIncrementalOutput());
363
+ $this->assertSame('', $p->$getIncrementalOutput());
364
+
365
+ flock($h, LOCK_UN);
366
+ }
367
+
368
+ fclose($h);
369
+ }
370
+
371
+ public function provideIncrementalOutput()
372
+ {
373
+ return array(
374
+ array('getOutput', 'getIncrementalOutput', 'php://stdout'),
375
+ array('getErrorOutput', 'getIncrementalErrorOutput', 'php://stderr'),
376
+ );
377
+ }
378
+
379
+ public function testGetOutput()
380
+ {
381
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n = 0; while ($n < 3) { echo \' foo \'; $n++; }')));
382
+
383
+ $p->run();
384
+ $this->assertEquals(3, preg_match_all('/foo/', $p->getOutput(), $matches));
385
+ }
386
+
387
+ public function testFlushOutput()
388
+ {
389
+ $p = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('$n=0;while ($n<3) {echo \' foo \';$n++;}')));
390
+
391
+ $p->run();
392
+ $p->clearOutput();
393
+ $this->assertEmpty($p->getOutput());
394
+ }
395
+
396
+ public function testZeroAsOutput()
397
+ {
398
+ if ('\\' === DIRECTORY_SEPARATOR) {
399
+ // see http://stackoverflow.com/questions/7105433/windows-batch-echo-without-new-line
400
+ $p = $this->getProcess('echo | set /p dummyName=0');
401
+ } else {
402
+ $p = $this->getProcess('printf 0');
403
+ }
404
+
405
+ $p->run();
406
+ $this->assertSame('0', $p->getOutput());
407
+ }
408
+
409
+ public function testExitCodeCommandFailed()
410
+ {
411
+ if ('\\' === DIRECTORY_SEPARATOR) {
412
+ $this->markTestSkipped('Windows does not support POSIX exit code');
413
+ }
414
+ $this->skipIfNotEnhancedSigchild();
415
+
416
+ // such command run in bash return an exitcode 127
417
+ $process = $this->getProcess('nonexistingcommandIhopeneversomeonewouldnameacommandlikethis');
418
+ $process->run();
419
+
420
+ $this->assertGreaterThan(0, $process->getExitCode());
421
+ }
422
+
423
+ public function testTTYCommand()
424
+ {
425
+ if ('\\' === DIRECTORY_SEPARATOR) {
426
+ $this->markTestSkipped('Windows does not have /dev/tty support');
427
+ }
428
+
429
+ $process = $this->getProcess('echo "foo" >> /dev/null && '.self::$phpBin.' -r "usleep(100000);"');
430
+ $process->setTty(true);
431
+ $process->start();
432
+ $this->assertTrue($process->isRunning());
433
+ $process->wait();
434
+
435
+ $this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
436
+ }
437
+
438
+ public function testTTYCommandExitCode()
439
+ {
440
+ if ('\\' === DIRECTORY_SEPARATOR) {
441
+ $this->markTestSkipped('Windows does have /dev/tty support');
442
+ }
443
+ $this->skipIfNotEnhancedSigchild();
444
+
445
+ $process = $this->getProcess('echo "foo" >> /dev/null');
446
+ $process->setTty(true);
447
+ $process->run();
448
+
449
+ $this->assertTrue($process->isSuccessful());
450
+ }
451
+
452
+ /**
453
+ * @expectedException \Symfony\Component\Process\Exception\RuntimeException
454
+ * @expectedExceptionMessage TTY mode is not supported on Windows platform.
455
+ */
456
+ public function testTTYInWindowsEnvironment()
457
+ {
458
+ if ('\\' !== DIRECTORY_SEPARATOR) {
459
+ $this->markTestSkipped('This test is for Windows platform only');
460
+ }
461
+
462
+ $process = $this->getProcess('echo "foo" >> /dev/null');
463
+ $process->setTty(false);
464
+ $process->setTty(true);
465
+ }
466
+
467
+ public function testExitCodeTextIsNullWhenExitCodeIsNull()
468
+ {
469
+ $this->skipIfNotEnhancedSigchild();
470
+
471
+ $process = $this->getProcess('');
472
+ $this->assertNull($process->getExitCodeText());
473
+ }
474
+
475
+ public function testPTYCommand()
476
+ {
477
+ if (!Process::isPtySupported()) {
478
+ $this->markTestSkipped('PTY is not supported on this operating system.');
479
+ }
480
+
481
+ $process = $this->getProcess('echo "foo"');
482
+ $process->setPty(true);
483
+ $process->run();
484
+
485
+ $this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
486
+ $this->assertEquals("foo\r\n", $process->getOutput());
487
+ }
488
+
489
+ public function testMustRun()
490
+ {
491
+ $this->skipIfNotEnhancedSigchild();
492
+
493
+ $process = $this->getProcess('echo foo');
494
+
495
+ $this->assertSame($process, $process->mustRun());
496
+ $this->assertEquals('foo'.PHP_EOL, $process->getOutput());
497
+ }
498
+
499
+ public function testSuccessfulMustRunHasCorrectExitCode()
500
+ {
501
+ $this->skipIfNotEnhancedSigchild();
502
+
503
+ $process = $this->getProcess('echo foo')->mustRun();
504
+ $this->assertEquals(0, $process->getExitCode());
505
+ }
506
+
507
+ /**
508
+ * @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
509
+ */
510
+ public function testMustRunThrowsException()
511
+ {
512
+ $this->skipIfNotEnhancedSigchild();
513
+
514
+ $process = $this->getProcess('exit 1');
515
+ $process->mustRun();
516
+ }
517
+
518
+ public function testExitCodeText()
519
+ {
520
+ $this->skipIfNotEnhancedSigchild();
521
+
522
+ $process = $this->getProcess('');
523
+ $r = new \ReflectionObject($process);
524
+ $p = $r->getProperty('exitcode');
525
+ $p->setAccessible(true);
526
+
527
+ $p->setValue($process, 2);
528
+ $this->assertEquals('Misuse of shell builtins', $process->getExitCodeText());
529
+ }
530
+
531
+ public function testStartIsNonBlocking()
532
+ {
533
+ $process = $this->getProcess(self::$phpBin.' -r "usleep(500000);"');
534
+ $start = microtime(true);
535
+ $process->start();
536
+ $end = microtime(true);
537
+ $this->assertLessThan(0.4, $end - $start);
538
+ $process->stop();
539
+ }
540
+
541
+ public function testUpdateStatus()
542
+ {
543
+ $process = $this->getProcess('echo foo');
544
+ $process->run();
545
+ $this->assertTrue(strlen($process->getOutput()) > 0);
546
+ }
547
+
548
+ public function testGetExitCodeIsNullOnStart()
549
+ {
550
+ $this->skipIfNotEnhancedSigchild();
551
+
552
+ $process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
553
+ $this->assertNull($process->getExitCode());
554
+ $process->start();
555
+ $this->assertNull($process->getExitCode());
556
+ $process->wait();
557
+ $this->assertEquals(0, $process->getExitCode());
558
+ }
559
+
560
+ public function testGetExitCodeIsNullOnWhenStartingAgain()
561
+ {
562
+ $this->skipIfNotEnhancedSigchild();
563
+
564
+ $process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
565
+ $process->run();
566
+ $this->assertEquals(0, $process->getExitCode());
567
+ $process->start();
568
+ $this->assertNull($process->getExitCode());
569
+ $process->wait();
570
+ $this->assertEquals(0, $process->getExitCode());
571
+ }
572
+
573
+ public function testGetExitCode()
574
+ {
575
+ $this->skipIfNotEnhancedSigchild();
576
+
577
+ $process = $this->getProcess('echo foo');
578
+ $process->run();
579
+ $this->assertSame(0, $process->getExitCode());
580
+ }
581
+
582
+ public function testStatus()
583
+ {
584
+ $process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
585
+ $this->assertFalse($process->isRunning());
586
+ $this->assertFalse($process->isStarted());
587
+ $this->assertFalse($process->isTerminated());
588
+ $this->assertSame(Process::STATUS_READY, $process->getStatus());
589
+ $process->start();
590
+ $this->assertTrue($process->isRunning());
591
+ $this->assertTrue($process->isStarted());
592
+ $this->assertFalse($process->isTerminated());
593
+ $this->assertSame(Process::STATUS_STARTED, $process->getStatus());
594
+ $process->wait();
595
+ $this->assertFalse($process->isRunning());
596
+ $this->assertTrue($process->isStarted());
597
+ $this->assertTrue($process->isTerminated());
598
+ $this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
599
+ }
600
+
601
+ public function testStop()
602
+ {
603
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(31);"');
604
+ $process->start();
605
+ $this->assertTrue($process->isRunning());
606
+ $process->stop();
607
+ $this->assertFalse($process->isRunning());
608
+ }
609
+
610
+ public function testIsSuccessful()
611
+ {
612
+ $this->skipIfNotEnhancedSigchild();
613
+
614
+ $process = $this->getProcess('echo foo');
615
+ $process->run();
616
+ $this->assertTrue($process->isSuccessful());
617
+ }
618
+
619
+ public function testIsSuccessfulOnlyAfterTerminated()
620
+ {
621
+ $this->skipIfNotEnhancedSigchild();
622
+
623
+ $process = $this->getProcess(self::$phpBin.' -r "usleep(100000);"');
624
+ $process->start();
625
+
626
+ $this->assertFalse($process->isSuccessful());
627
+
628
+ $process->wait();
629
+
630
+ $this->assertTrue($process->isSuccessful());
631
+ }
632
+
633
+ public function testIsNotSuccessful()
634
+ {
635
+ $this->skipIfNotEnhancedSigchild();
636
+
637
+ $process = $this->getProcess(self::$phpBin.' -r "throw new \Exception(\'BOUM\');"');
638
+ $process->run();
639
+ $this->assertFalse($process->isSuccessful());
640
+ }
641
+
642
+ public function testProcessIsNotSignaled()
643
+ {
644
+ if ('\\' === DIRECTORY_SEPARATOR) {
645
+ $this->markTestSkipped('Windows does not support POSIX signals');
646
+ }
647
+ $this->skipIfNotEnhancedSigchild();
648
+
649
+ $process = $this->getProcess('echo foo');
650
+ $process->run();
651
+ $this->assertFalse($process->hasBeenSignaled());
652
+ }
653
+
654
+ public function testProcessWithoutTermSignal()
655
+ {
656
+ if ('\\' === DIRECTORY_SEPARATOR) {
657
+ $this->markTestSkipped('Windows does not support POSIX signals');
658
+ }
659
+ $this->skipIfNotEnhancedSigchild();
660
+
661
+ $process = $this->getProcess('echo foo');
662
+ $process->run();
663
+ $this->assertEquals(0, $process->getTermSignal());
664
+ }
665
+
666
+ public function testProcessIsSignaledIfStopped()
667
+ {
668
+ if ('\\' === DIRECTORY_SEPARATOR) {
669
+ $this->markTestSkipped('Windows does not support POSIX signals');
670
+ }
671
+ $this->skipIfNotEnhancedSigchild();
672
+
673
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(32);"');
674
+ $process->start();
675
+ $process->stop();
676
+ $this->assertTrue($process->hasBeenSignaled());
677
+ $this->assertEquals(15, $process->getTermSignal()); // SIGTERM
678
+ }
679
+
680
+ /**
681
+ * @expectedException \Symfony\Component\Process\Exception\RuntimeException
682
+ * @expectedExceptionMessage The process has been signaled
683
+ */
684
+ public function testProcessThrowsExceptionWhenExternallySignaled()
685
+ {
686
+ if (!function_exists('posix_kill')) {
687
+ $this->markTestSkipped('Function posix_kill is required.');
688
+ }
689
+ $this->skipIfNotEnhancedSigchild(false);
690
+
691
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(32.1)"');
692
+ $process->start();
693
+ posix_kill($process->getPid(), 9); // SIGKILL
694
+
695
+ $process->wait();
696
+ }
697
+
698
+ public function testRestart()
699
+ {
700
+ $process1 = $this->getProcess(self::$phpBin.' -r "echo getmypid();"');
701
+ $process1->run();
702
+ $process2 = $process1->restart();
703
+
704
+ $process2->wait(); // wait for output
705
+
706
+ // Ensure that both processed finished and the output is numeric
707
+ $this->assertFalse($process1->isRunning());
708
+ $this->assertFalse($process2->isRunning());
709
+ $this->assertTrue(is_numeric($process1->getOutput()));
710
+ $this->assertTrue(is_numeric($process2->getOutput()));
711
+
712
+ // Ensure that restart returned a new process by check that the output is different
713
+ $this->assertNotEquals($process1->getOutput(), $process2->getOutput());
714
+ }
715
+
716
+ /**
717
+ * @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
718
+ * @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
719
+ */
720
+ public function testRunProcessWithTimeout()
721
+ {
722
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(30);"');
723
+ $process->setTimeout(0.1);
724
+ $start = microtime(true);
725
+ try {
726
+ $process->run();
727
+ $this->fail('A RuntimeException should have been raised');
728
+ } catch (RuntimeException $e) {
729
+ }
730
+
731
+ $this->assertLessThan(15, microtime(true) - $start);
732
+
733
+ throw $e;
734
+ }
735
+
736
+ public function testCheckTimeoutOnNonStartedProcess()
737
+ {
738
+ $process = $this->getProcess('echo foo');
739
+ $this->assertNull($process->checkTimeout());
740
+ }
741
+
742
+ public function testCheckTimeoutOnTerminatedProcess()
743
+ {
744
+ $process = $this->getProcess('echo foo');
745
+ $process->run();
746
+ $this->assertNull($process->checkTimeout());
747
+ }
748
+
749
+ /**
750
+ * @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
751
+ * @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
752
+ */
753
+ public function testCheckTimeoutOnStartedProcess()
754
+ {
755
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(33);"');
756
+ $process->setTimeout(0.1);
757
+
758
+ $process->start();
759
+ $start = microtime(true);
760
+
761
+ try {
762
+ while ($process->isRunning()) {
763
+ $process->checkTimeout();
764
+ usleep(100000);
765
+ }
766
+ $this->fail('A ProcessTimedOutException should have been raised');
767
+ } catch (ProcessTimedOutException $e) {
768
+ }
769
+
770
+ $this->assertLessThan(15, microtime(true) - $start);
771
+
772
+ throw $e;
773
+ }
774
+
775
+ public function testIdleTimeout()
776
+ {
777
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(34);"');
778
+ $process->setTimeout(60);
779
+ $process->setIdleTimeout(0.1);
780
+
781
+ try {
782
+ $process->run();
783
+
784
+ $this->fail('A timeout exception was expected.');
785
+ } catch (ProcessTimedOutException $e) {
786
+ $this->assertTrue($e->isIdleTimeout());
787
+ $this->assertFalse($e->isGeneralTimeout());
788
+ $this->assertEquals(0.1, $e->getExceededTimeout());
789
+ }
790
+ }
791
+
792
+ public function testIdleTimeoutNotExceededWhenOutputIsSent()
793
+ {
794
+ if ('\\' === DIRECTORY_SEPARATOR) {
795
+ $this->markTestIncomplete('This test fails with a timeout on Windows, can someone investigate please?');
796
+ }
797
+ $process = $this->getProcess(sprintf('%s -r %s', self::$phpBin, escapeshellarg('while (true) {echo "foo\n"; usleep(10000);}')));
798
+ $process->setTimeout(1);
799
+ $process->start();
800
+
801
+ while (false === strpos($process->getOutput(), 'foo')) {
802
+ usleep(1000);
803
+ }
804
+
805
+ $process->setIdleTimeout(0.1);
806
+
807
+ try {
808
+ $process->wait();
809
+ $this->fail('A timeout exception was expected.');
810
+ } catch (ProcessTimedOutException $ex) {
811
+ $this->assertTrue($ex->isGeneralTimeout(), 'A general timeout is expected.');
812
+ $this->assertFalse($ex->isIdleTimeout(), 'No idle timeout is expected.');
813
+ $this->assertEquals(1, $ex->getExceededTimeout());
814
+ }
815
+ }
816
+
817
+ /**
818
+ * @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
819
+ * @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
820
+ */
821
+ public function testStartAfterATimeout()
822
+ {
823
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(35);"');
824
+ $process->setTimeout(0.1);
825
+
826
+ try {
827
+ $process->run();
828
+ $this->fail('A ProcessTimedOutException should have been raised.');
829
+ } catch (ProcessTimedOutException $e) {
830
+ }
831
+ $this->assertFalse($process->isRunning());
832
+ $process->start();
833
+ $this->assertTrue($process->isRunning());
834
+ $process->stop(0);
835
+
836
+ throw $e;
837
+ }
838
+
839
+ public function testGetPid()
840
+ {
841
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(36);"');
842
+ $process->start();
843
+ $this->assertGreaterThan(0, $process->getPid());
844
+ $process->stop(0);
845
+ }
846
+
847
+ public function testGetPidIsNullBeforeStart()
848
+ {
849
+ $process = $this->getProcess('foo');
850
+ $this->assertNull($process->getPid());
851
+ }
852
+
853
+ public function testGetPidIsNullAfterRun()
854
+ {
855
+ $process = $this->getProcess('echo foo');
856
+ $process->run();
857
+ $this->assertNull($process->getPid());
858
+ }
859
+
860
+ /**
861
+ * @requires extension pcntl
862
+ */
863
+ public function testSignal()
864
+ {
865
+ $process = $this->getProcess(self::$phpBin.' '.__DIR__.'/SignalListener.php');
866
+ $process->start();
867
+
868
+ while (false === strpos($process->getOutput(), 'Caught')) {
869
+ usleep(1000);
870
+ }
871
+ $process->signal(SIGUSR1);
872
+ $process->wait();
873
+
874
+ $this->assertEquals('Caught SIGUSR1', $process->getOutput());
875
+ }
876
+
877
+ /**
878
+ * @requires extension pcntl
879
+ */
880
+ public function testExitCodeIsAvailableAfterSignal()
881
+ {
882
+ $this->skipIfNotEnhancedSigchild();
883
+
884
+ $process = $this->getProcess('sleep 4');
885
+ $process->start();
886
+ $process->signal(SIGKILL);
887
+
888
+ while ($process->isRunning()) {
889
+ usleep(10000);
890
+ }
891
+
892
+ $this->assertFalse($process->isRunning());
893
+ $this->assertTrue($process->hasBeenSignaled());
894
+ $this->assertFalse($process->isSuccessful());
895
+ $this->assertEquals(137, $process->getExitCode());
896
+ }
897
+
898
+ /**
899
+ * @expectedException \Symfony\Component\Process\Exception\LogicException
900
+ * @expectedExceptionMessage Can not send signal on a non running process.
901
+ */
902
+ public function testSignalProcessNotRunning()
903
+ {
904
+ $process = $this->getProcess('foo');
905
+ $process->signal(1); // SIGHUP
906
+ }
907
+
908
+ /**
909
+ * @dataProvider provideMethodsThatNeedARunningProcess
910
+ */
911
+ public function testMethodsThatNeedARunningProcess($method)
912
+ {
913
+ $process = $this->getProcess('foo');
914
+ $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method));
915
+ $process->{$method}();
916
+ }
917
+
918
+ public function provideMethodsThatNeedARunningProcess()
919
+ {
920
+ return array(
921
+ array('getOutput'),
922
+ array('getIncrementalOutput'),
923
+ array('getErrorOutput'),
924
+ array('getIncrementalErrorOutput'),
925
+ array('wait'),
926
+ );
927
+ }
928
+
929
+ /**
930
+ * @dataProvider provideMethodsThatNeedATerminatedProcess
931
+ * @expectedException Symfony\Component\Process\Exception\LogicException
932
+ * @expectedExceptionMessage Process must be terminated before calling
933
+ */
934
+ public function testMethodsThatNeedATerminatedProcess($method)
935
+ {
936
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(37);"');
937
+ $process->start();
938
+ try {
939
+ $process->{$method}();
940
+ $process->stop(0);
941
+ $this->fail('A LogicException must have been thrown');
942
+ } catch (\Exception $e) {
943
+ }
944
+ $process->stop(0);
945
+
946
+ throw $e;
947
+ }
948
+
949
+ public function provideMethodsThatNeedATerminatedProcess()
950
+ {
951
+ return array(
952
+ array('hasBeenSignaled'),
953
+ array('getTermSignal'),
954
+ array('hasBeenStopped'),
955
+ array('getStopSignal'),
956
+ );
957
+ }
958
+
959
+ /**
960
+ * @dataProvider provideWrongSignal
961
+ * @expectedException \Symfony\Component\Process\Exception\RuntimeException
962
+ */
963
+ public function testWrongSignal($signal)
964
+ {
965
+ if ('\\' === DIRECTORY_SEPARATOR) {
966
+ $this->markTestSkipped('POSIX signals do not work on Windows');
967
+ }
968
+
969
+ $process = $this->getProcess(self::$phpBin.' -r "sleep(38);"');
970
+ $process->start();
971
+ try {
972
+ $process->signal($signal);
973
+ $this->fail('A RuntimeException must have been thrown');
974
+ } catch (RuntimeException $e) {
975
+ $process->stop(0);
976
+ }
977
+
978
+ throw $e;
979
+ }
980
+
981
+ public function provideWrongSignal()
982
+ {
983
+ return array(
984
+ array(-4),
985
+ array('Céphalopodes'),
986
+ );
987
+ }
988
+
989
+ public function testDisableOutputDisablesTheOutput()
990
+ {
991
+ $p = $this->getProcess('foo');
992
+ $this->assertFalse($p->isOutputDisabled());
993
+ $p->disableOutput();
994
+ $this->assertTrue($p->isOutputDisabled());
995
+ $p->enableOutput();
996
+ $this->assertFalse($p->isOutputDisabled());
997
+ }
998
+
999
+ /**
1000
+ * @expectedException \Symfony\Component\Process\Exception\RuntimeException
1001
+ * @expectedExceptionMessage Disabling output while the process is running is not possible.
1002
+ */
1003
+ public function testDisableOutputWhileRunningThrowsException()
1004
+ {
1005
+ $p = $this->getProcess(self::$phpBin.' -r "sleep(39);"');
1006
+ $p->start();
1007
+ $p->disableOutput();
1008
+ }
1009
+
1010
+ /**
1011
+ * @expectedException \Symfony\Component\Process\Exception\RuntimeException
1012
+ * @expectedExceptionMessage Enabling output while the process is running is not possible.
1013
+ */
1014
+ public function testEnableOutputWhileRunningThrowsException()
1015
+ {
1016
+ $p = $this->getProcess(self::$phpBin.' -r "sleep(40);"');
1017
+ $p->disableOutput();
1018
+ $p->start();
1019
+ $p->enableOutput();
1020
+ }
1021
+
1022
+ public function testEnableOrDisableOutputAfterRunDoesNotThrowException()
1023
+ {
1024
+ $p = $this->getProcess('echo foo');
1025
+ $p->disableOutput();
1026
+ $p->run();
1027
+ $p->enableOutput();
1028
+ $p->disableOutput();
1029
+ $this->assertTrue($p->isOutputDisabled());
1030
+ }
1031
+
1032
+ /**
1033
+ * @expectedException \Symfony\Component\Process\Exception\LogicException
1034
+ * @expectedExceptionMessage Output can not be disabled while an idle timeout is set.
1035
+ */
1036
+ public function testDisableOutputWhileIdleTimeoutIsSet()
1037
+ {
1038
+ $process = $this->getProcess('foo');
1039
+ $process->setIdleTimeout(1);
1040
+ $process->disableOutput();
1041
+ }
1042
+
1043
+ /**
1044
+ * @expectedException \Symfony\Component\Process\Exception\LogicException
1045
+ * @expectedExceptionMessage timeout can not be set while the output is disabled.
1046
+ */
1047
+ public function testSetIdleTimeoutWhileOutputIsDisabled()
1048
+ {
1049
+ $process = $this->getProcess('foo');
1050
+ $process->disableOutput();
1051
+ $process->setIdleTimeout(1);
1052
+ }
1053
+
1054
+ public function testSetNullIdleTimeoutWhileOutputIsDisabled()
1055
+ {
1056
+ $process = $this->getProcess('foo');
1057
+ $process->disableOutput();
1058
+ $this->assertSame($process, $process->setIdleTimeout(null));
1059
+ }
1060
+
1061
+ /**
1062
+ * @dataProvider provideStartMethods
1063
+ */
1064
+ public function testStartWithACallbackAndDisabledOutput($startMethod, $exception, $exceptionMessage)
1065
+ {
1066
+ $p = $this->getProcess('foo');
1067
+ $p->disableOutput();
1068
+ $this->setExpectedException($exception, $exceptionMessage);
1069
+ if ('mustRun' === $startMethod) {
1070
+ $this->skipIfNotEnhancedSigchild();
1071
+ }
1072
+ $p->{$startMethod}(function () {});
1073
+ }
1074
+
1075
+ public function provideStartMethods()
1076
+ {
1077
+ return array(
1078
+ array('start', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'),
1079
+ array('run', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'),
1080
+ array('mustRun', 'Symfony\Component\Process\Exception\LogicException', 'Output has been disabled, enable it to allow the use of a callback.'),
1081
+ );
1082
+ }
1083
+
1084
+ /**
1085
+ * @dataProvider provideOutputFetchingMethods
1086
+ * @expectedException \Symfony\Component\Process\Exception\LogicException
1087
+ * @expectedExceptionMessage Output has been disabled.
1088
+ */
1089
+ public function testGetOutputWhileDisabled($fetchMethod)
1090
+ {
1091
+ $p = $this->getProcess(self::$phpBin.' -r "sleep(41);"');
1092
+ $p->disableOutput();
1093
+ $p->start();
1094
+ $p->{$fetchMethod}();
1095
+ }
1096
+
1097
+ public function provideOutputFetchingMethods()
1098
+ {
1099
+ return array(
1100
+ array('getOutput'),
1101
+ array('getIncrementalOutput'),
1102
+ array('getErrorOutput'),
1103
+ array('getIncrementalErrorOutput'),
1104
+ );
1105
+ }
1106
+
1107
+ public function testStopTerminatesProcessCleanly()
1108
+ {
1109
+ $process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(42);"');
1110
+ $process->run(function () use ($process) {
1111
+ $process->stop();
1112
+ });
1113
+ $this->assertTrue(true, 'A call to stop() is not expected to cause wait() to throw a RuntimeException');
1114
+ }
1115
+
1116
+ public function testKillSignalTerminatesProcessCleanly()
1117
+ {
1118
+ $process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(43);"');
1119
+ $process->run(function () use ($process) {
1120
+ $process->signal(9); // SIGKILL
1121
+ });
1122
+ $this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
1123
+ }
1124
+
1125
+ public function testTermSignalTerminatesProcessCleanly()
1126
+ {
1127
+ $process = $this->getProcess(self::$phpBin.' -r "echo 123; sleep(44);"');
1128
+ $process->run(function () use ($process) {
1129
+ $process->signal(15); // SIGTERM
1130
+ });
1131
+ $this->assertTrue(true, 'A call to signal() is not expected to cause wait() to throw a RuntimeException');
1132
+ }
1133
+
1134
+ public function responsesCodeProvider()
1135
+ {
1136
+ return array(
1137
+ //expected output / getter / code to execute
1138
+ //array(1,'getExitCode','exit(1);'),
1139
+ //array(true,'isSuccessful','exit();'),
1140
+ array('output', 'getOutput', 'echo \'output\';'),
1141
+ );
1142
+ }
1143
+
1144
+ public function pipesCodeProvider()
1145
+ {
1146
+ $variations = array(
1147
+ 'fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);',
1148
+ 'include \''.__DIR__.'/PipeStdinInStdoutStdErrStreamSelect.php\';',
1149
+ );
1150
+
1151
+ if ('\\' === DIRECTORY_SEPARATOR) {
1152
+ // Avoid XL buffers on Windows because of https://bugs.php.net/bug.php?id=65650
1153
+ $sizes = array(1, 2, 4, 8);
1154
+ } else {
1155
+ $sizes = array(1, 16, 64, 1024, 4096);
1156
+ }
1157
+
1158
+ $codes = array();
1159
+ foreach ($sizes as $size) {
1160
+ foreach ($variations as $code) {
1161
+ $codes[] = array($code, $size);
1162
+ }
1163
+ }
1164
+
1165
+ return $codes;
1166
+ }
1167
+
1168
+ /**
1169
+ * provides default method names for simple getter/setter.
1170
+ */
1171
+ public function methodProvider()
1172
+ {
1173
+ $defaults = array(
1174
+ array('CommandLine'),
1175
+ array('Timeout'),
1176
+ array('WorkingDirectory'),
1177
+ array('Env'),
1178
+ array('Stdin'),
1179
+ array('Input'),
1180
+ array('Options'),
1181
+ );
1182
+
1183
+ return $defaults;
1184
+ }
1185
+
1186
+ /**
1187
+ * @param string $commandline
1188
+ * @param null|string $cwd
1189
+ * @param null|array $env
1190
+ * @param null|string $input
1191
+ * @param int $timeout
1192
+ * @param array $options
1193
+ *
1194
+ * @return Process
1195
+ */
1196
+ private function getProcess($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
1197
+ {
1198
+ $process = new Process($commandline, $cwd, $env, $input, $timeout, $options);
1199
+
1200
+ if (false !== $enhance = getenv('ENHANCE_SIGCHLD')) {
1201
+ try {
1202
+ $process->setEnhanceSigchildCompatibility(false);
1203
+ $process->getExitCode();
1204
+ $this->fail('ENHANCE_SIGCHLD must be used together with a sigchild-enabled PHP.');
1205
+ } catch (RuntimeException $e) {
1206
+ $this->assertSame('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.', $e->getMessage());
1207
+ if ($enhance) {
1208
+ $process->setEnhanceSigChildCompatibility(true);
1209
+ } else {
1210
+ self::$notEnhancedSigchild = true;
1211
+ }
1212
+ }
1213
+ }
1214
+
1215
+ if (self::$process) {
1216
+ self::$process->stop(0);
1217
+ }
1218
+
1219
+ return self::$process = $process;
1220
+ }
1221
+
1222
+ private function skipIfNotEnhancedSigchild($expectException = true)
1223
+ {
1224
+ if (self::$sigchild) {
1225
+ if (!$expectException) {
1226
+ $this->markTestSkipped('PHP is compiled with --enable-sigchild.');
1227
+ } elseif (self::$notEnhancedSigchild) {
1228
+ $this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'This PHP has been compiled with --enable-sigchild.');
1229
+ }
1230
+ }
1231
+ }
1232
+ }
1233
+
1234
+ class Stringifiable
1235
+ {
1236
+ public function __toString()
1237
+ {
1238
+ return 'stringifiable';
1239
+ }
1240
+ }
1241
+
1242
+ class NonStringifiable
1243
+ {
1244
+ }
vendor/symfony/process/Tests/ProcessUtilsTest.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony\Component\Process\Tests;
13
+
14
+ use Symfony\Component\Process\ProcessUtils;
15
+
16
+ class ProcessUtilsTest extends \PHPUnit_Framework_TestCase
17
+ {
18
+ /**
19
+ * @dataProvider dataArguments
20
+ */
21
+ public function testEscapeArgument($result, $argument)
22
+ {
23
+ $this->assertSame($result, ProcessUtils::escapeArgument($argument));
24
+ }
25
+
26
+ public function dataArguments()
27
+ {
28
+ if ('\\' === DIRECTORY_SEPARATOR) {
29
+ return array(
30
+ array('"\"php\" \"-v\""', '"php" "-v"'),
31
+ array('"foo bar"', 'foo bar'),
32
+ array('^%"path"^%', '%path%'),
33
+ array('"<|>\\" \\"\'f"', '<|>" "\'f'),
34
+ array('""', ''),
35
+ array('"with\trailingbs\\\\"', 'with\trailingbs\\'),
36
+ );
37
+ }
38
+
39
+ return array(
40
+ array("'\"php\" \"-v\"'", '"php" "-v"'),
41
+ array("'foo bar'", 'foo bar'),
42
+ array("'%path%'", '%path%'),
43
+ array("'<|>\" \"'\\''f'", '<|>" "\'f'),
44
+ array("''", ''),
45
+ array("'with\\trailingbs\\'", 'with\trailingbs\\'),
46
+ );
47
+ }
48
+ }
vendor/symfony/process/Tests/SignalListener.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ pcntl_signal(SIGUSR1, function () {echo 'SIGUSR1'; exit;});
13
+
14
+ echo 'Caught ';
15
+
16
+ $n = 0;
17
+
18
+ while ($n++ < 400) {
19
+ usleep(10000);
20
+ pcntl_signal_dispatch();
21
+ }
vendor/symfony/process/composer.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "symfony/process",
3
+ "type": "library",
4
+ "description": "Symfony Process Component",
5
+ "keywords": [],
6
+ "homepage": "https://symfony.com",
7
+ "license": "MIT",
8
+ "authors": [
9
+ {
10
+ "name": "Fabien Potencier",
11
+ "email": "fabien@symfony.com"
12
+ },
13
+ {
14
+ "name": "Symfony Community",
15
+ "homepage": "https://symfony.com/contributors"
16
+ }
17
+ ],
18
+ "require": {
19
+ "php": ">=5.3.9"
20
+ },
21
+ "autoload": {
22
+ "psr-4": { "Symfony\\Component\\Process\\": "" },
23
+ "exclude-from-classmap": [
24
+ "/Tests/"
25
+ ]
26
+ },
27
+ "minimum-stability": "dev",
28
+ "extra": {
29
+ "branch-alias": {
30
+ "dev-master": "2.8-dev"
31
+ }
32
+ }
33
+ }
vendor/symfony/process/phpunit.xml.dist ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
5
+ backupGlobals="false"
6
+ colors="true"
7
+ bootstrap="vendor/autoload.php"
8
+ >
9
+ <php>
10
+ <ini name="error_reporting" value="-1" />
11
+ </php>
12
+
13
+ <testsuites>
14
+ <testsuite name="Symfony Process Component Test Suite">
15
+ <directory>./Tests/</directory>
16
+ </testsuite>
17
+ </testsuites>
18
+
19
+ <filter>
20
+ <whitelist>
21
+ <directory>./</directory>
22
+ <exclude>
23
+ <directory>./Tests</directory>
24
+ <directory>./vendor</directory>
25
+ </exclude>
26
+ </whitelist>
27
+ </filter>
28
+ </phpunit>