Skip to content

Commit

Permalink
slightly more polished refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmagicii committed Oct 13, 2024
1 parent d2d8d18 commit d6679eb
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/Nether/Console/ProcessRunner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php ##########################################################################
################################################################################

namespace Nether\Console;

################################################################################
################################################################################

class ProcessRunner {

public mixed
$Proc;

public string
$Line;

public array
$Pipe = [];

public bool
$Verbose;

public function
__Construct($Line, bool $Verbose=FALSE) {

$this->Line = $Line;
$this->Verbose = $Verbose;

return;
}

public function
Run():
static {

$this->Proc = proc_open(
$this->Line,
[ ['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w'] ],
$this->Pipe
);

return $this;
}

public function
IsOK():
bool {

return is_resource($this->Proc);
}

public function
Spin():
bool {

$Line = NULL;

while($this->IsOK())
while($Line = fgets($this->Pipe[1])) {

if($this->Verbose)
echo $Line;

continue;
}

return FALSE;
}

};

0 comments on commit d6679eb

Please sign in to comment.