Ferreteria/v0.6/clade/Sys/Data/Codec/aux/CmdLine
Jump to navigation
Jump to search
| ||||||||||||||||||||||
About
- Purpose: This is kind of a specialty thing for handling command-lines as either array or string data.
- Maybe there's a way to better integrate it into the Codec class-structure, but for now it's eluding me.
Thinking
- 2026-01-09
- Up to now, the data could be stored in either
arrayorstringformat, with the other format being calculated if needed. However... - Functionality to combine the contents of one CmdLine object with another (
EmbedWithin()) means that we need to decide on a default storage format -- array or string. I think I'm going with array. For now, switching from string will only be forced if combination is needed.
- Up to now, the data could be stored in either
History
Code
interface iCmdLine extends BaseIface {
// SETUP
static function FromString(string $s) : self;
static function FromArray(array $ar) : self;
// ACCESS: read
function AsString() : string;
function AsArray() : array;
// ACCESS: write
function EmbedWithin(SelfIface $oCmd);
}
class cCmdLine extends BaseClass implements SelfIface {
// ++ SETUP ++ //
public static function FromString(string $s) : SelfIface {
$oThis = new static;
$oThis->QString()->SetIt($s);
return $oThis;
}
public static function FromArray(array $a) : SelfIface {
$oThis = new static;
$oThis->QArray()->SetIt($a);
return $oThis;
}
// -- SETUP -- //
// ++ ACCESS: read ++ //
public function AsString() : string {
return $this->QString()->HasIt() ? $this->QString()->GetIt() : $this->ToString();
}
public function AsArray() : array {
return $this->QArray()->HasIt() ? $this->QArray()->GetIt() : $this->ToArray();
}
// ++ ACCESS: write ++ //
// ACTION:
public function EmbedWithin(SelfIface $oPfx, ?SelfIface $oSfx=NULL) {
$arNew = array_merge($oPfx->
}
// ++ ACCESS (internal): storage ++ //
private $qsCmd=NULL;
protected function QString() : QStrIface { return $this->qsCmd ?? ($this->qsCmd = QStrClass::AsNew()); }
private $qaCmd=NULL;
protected function QArray() : QArrIface { return $this->qaCmd ?? ($this->qaCmd = QArrClass::AsNew()); }
// ++ ACCESS (internal): conversion ++ //
// PURPOSE: Command is stored as an array -- convert to string.
protected function ToString() : string {
$ar = $this->QArray()->GetIt();
$s = NULL;
foreach ($ar as $sPiece) {
if (is_string($s)) $s .= ' ';
$s .= escapeshellarg($sPiece);
}
return $s;
}
// PURPOSE: Command is stored as a string -- convert to array.
protected function ToArray() : array {
$s = $this->QString()->GetIt();
$oParser = new ParserClass;
$oGene = $oParser->Parse();
return $oGene->AsStringArray();
}
// -- ACCESS -- //
}