MediaWiki  master
DumpPipeOutput.php
Go to the documentation of this file.
1 <?php
29 
34  protected $command, $filename;
36  protected $procOpenResource = false;
37 
42  public function __construct( $command, $file = null ) {
43  if ( !is_null( $file ) ) {
44  $command .= " > " . Shell::escape( $file );
45  }
46 
47  $this->startCommand( $command );
48  $this->command = $command;
49  $this->filename = $file;
50  }
51 
55  function writeCloseStream( $string ) {
56  parent::writeCloseStream( $string );
57  if ( $this->procOpenResource ) {
58  proc_close( $this->procOpenResource );
59  $this->procOpenResource = false;
60  }
61  }
62 
66  function startCommand( $command ) {
67  $spec = [
68  0 => [ "pipe", "r" ],
69  ];
70  $pipes = [];
71  $this->procOpenResource = proc_open( $command, $spec, $pipes );
72  $this->handle = $pipes[0];
73  }
74 
78  function closeRenameAndReopen( $newname ) {
79  $this->closeAndRename( $newname, true );
80  }
81 
85  function closeAndRename( $newname, $open = false ) {
86  $newname = $this->checkRenameArgCount( $newname );
87  if ( $newname ) {
88  if ( $this->handle ) {
89  fclose( $this->handle );
90  $this->handle = false;
91  }
92  if ( $this->procOpenResource ) {
93  proc_close( $this->procOpenResource );
94  $this->procOpenResource = false;
95  }
96  $this->renameOrException( $newname );
97  if ( $open ) {
99  $command .= " > " . Shell::escape( $this->filename );
100  $this->startCommand( $command );
101  }
102  }
103  }
104 }
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
resource bool $procOpenResource
startCommand( $command)
renameOrException( $newname)
writeCloseStream( $string)
closeRenameAndReopen( $newname)
__construct( $command, $file=null)
closeAndRename( $newname, $open=false)
checkRenameArgCount( $newname)