interface iPool extends BaseIface {
function CountOpen() : int;
function Block(bool $bBlock) : int;
function Shut() : int;
}
abstract class caPool extends BaseClass implements iPool {
// ++ CONFIG ++ //
abstract protected function StreamClass(int $nPipe) : string;
// -- CONFIG -- //
// ++ OBJECTS ++ //
private $aoStm = [];
protected function AOStreams() : array { return $this->aoStm; } // array of Stream objects
protected function StreamIt(int $n, ?string $sName=NULL) : StreamIface {
$ao = $this->AOStreams();
if (array_key_exists($n,$ao)) {
$o = $ao[$n];
} else {
self::HardAssert(is_string($sName),'Internal Error: trying to create Stream object with no name.');
$o = ($this->StreamClass($n))::FromNative($this->GetIt($n),$sName);
$this->aoStm[$n] = $o;
}
return $o;
}
// -- OBJECTS -- //
// ++ ACTION ++ //
public function Block(bool $bBlock) : int {
$ar = $this->GetVals();
$n = 0;
foreach ($ar as $rPipe) {
$ok = stream_set_blocking($rPipe,$bBlock);
if ($ok) $n++;
$sOn = $bBlock ? 'ON' : 'off';
$sOk = $ok ? 'OK' : 'ERR!';
$sVar = self::DiagnoseValue($rPipe);
}
return $n;
}
public function Shut() : int {
$ar = $this->GetVals();
$n = 0;
foreach ($ar as $rPipe) {
$ok = fclose($rPipe);
if ($ok) $n++;
}
return $n;
}
public function CountOpen() : int {
$ar = $this->GetVals();
$n = 0;
foreach ($ar as $ndx => $rPipe) {
$arStat = fstat($rPipe);
if (is_array($arStat)) {
$n++;
} else {
echo "PIPE #$ndx is closed.".CRLF;
}
}
return $n;
}
// -- ACTION -- //
}