MediaWiki master
DumpPipeOutput.php
Go to the documentation of this file.
1<?php
15
21 protected $command;
23 protected $filename;
25 protected $procOpenResource = false;
26
31 public function __construct( $command, $file = null ) {
32 if ( $file !== null ) {
33 $command .= " > " . Shell::escape( $file );
34 }
35
36 $this->startCommand( $command );
37 $this->command = $command;
38 $this->filename = $file;
39 }
40
44 public function writeCloseStream( $string ) {
45 parent::writeCloseStream( $string );
46 if ( $this->procOpenResource ) {
47 proc_close( $this->procOpenResource );
48 $this->procOpenResource = false;
49 }
50 }
51
55 public function startCommand( $command ) {
56 $spec = [
57 0 => [ "pipe", "r" ],
58 ];
59 $pipes = [];
60 $this->procOpenResource = proc_open( $command, $spec, $pipes );
61 $this->handle = $pipes[0];
62 }
63
67 public function closeRenameAndReopen( $newname ) {
68 $this->closeAndRename( $newname, true );
69 }
70
74 public function closeAndRename( $newname, $open = false ) {
75 $newname = $this->checkRenameArgCount( $newname );
76 if ( $newname ) {
77 if ( $this->handle ) {
78 fclose( $this->handle );
79 $this->handle = false;
80 }
81 if ( $this->procOpenResource ) {
82 proc_close( $this->procOpenResource );
83 $this->procOpenResource = false;
84 }
85 $this->renameOrException( $newname );
86 if ( $open ) {
88 $command .= " > " . Shell::escape( $this->filename );
89 $this->startCommand( $command );
90 }
91 }
92 }
93}
checkRenameArgCount( $newname)
renameOrException( $newname)
closeAndRename( $newname, $open=false)
Close the old file, and move it to a specified name.Use this for the last piece of a file written out...
writeCloseStream( $string)
startCommand( $command)
__construct( $command, $file=null)
closeRenameAndReopen( $newname)
Close the old file, move it to a specified name, and reopen new file with the old name....
string null $filename
resource false $procOpenResource
Executes shell commands.
Definition Shell.php:32