Ferreteria/v0.6/clade/Sys/FileSys/Aspect/Ident/spex/PSpecChain/@code/2025/12/15
| 2025/12/14 | 2025/12/15 | 2025/12/16 |
interface iChain extends BaseIface, QStrIface {
// SETUP
static function FromSpec(string $fs) : iChain;
// ACCESS
function QOBase() : QObjIface; // first piece in series
function QOLeaf() : QObjIface; // final piece in series
function FigureRelative(string $fsFull) : QStrIface;
// ACTION
function AddSegment(string $fn) : TwigIface;
function ParsePath(string $fp) : TwigIface;
}
class cChain extends BaseClass implements iChain {
use QStrTrait;
// ++ SETUP ++ //
static public function FromSpec(string $fs) : iChain {
$oThis = new static;
$oThis->ParsePath($fs);
return $oThis;
}
// -- SETUP -- //
// ++ OBJECTS ++ //
private $qoBase;
public function QOBase() : QObjIface { return $this->qoBase ?? ($this->qoBase = QObjClass::AsNew()); }
private $qoLeaf;
public function QOLeaf() : QObjIface { return $this->qoLeaf ?? ($this->qoLeaf = QObjClass::AsNew()); }
// -- OBJECTS -- //
// ++ ACCESS ++ //
private $qsPath = NULL;
public function QSPath() : QStrIface {
$qsPath = $this->qsPath ?? ($this->qsPath = QStrClass::AsNew());
$qoLeaf = $this->QOLeaf();
if ($qoLeaf->HasIt()) {
$oLeaf = $qoLeaf->GetIt();
$fs = $oLeaf->SpecAbs();
$qsPath->SetIt($fs);
}
return $qsPath; // 2025-11-08 This is returning as not set.
}
// ++ ACCESS: figuring ++ //
public function FigureRelative(string $fsFull) : QStrIface {
if ($this->HasIt()) {
$fpThis = $this->GetIt();
if (str_starts_with($fsFull,$fpThis)) {
// get the part of $fsFull *after* that base path
$nlThis = strlen($fpThis);
$fpRemain = substr($fsFull,$nlThis);
$qs = QStrClass::FromString($fpRemain);
}
} else {
$qs = QStrClass::AsNew();
}
return $qs;
}
// ++ ACCESS: QStr ++ //
public function HasStr() : bool {
return $this->QOLeaf()->HasIt();
}
public function SetStr(string $s) {
$this->ParsePath($s);
}
public function &GetStr() : string {
#$this->AmHere();
$qsSpec = $this->QSPath();
#echo $oPath->ReflectThis()->Report();
if ($qsSpec->HasIt()) {
$sSpec = $qsSpec->GetIt();
} else {
echo self::Screen()->ErrorIt('Internal Error').": trying to retrieve path that hasn't been set.".CRLF;
}
return $sSpec;
}
// -- ACCESS -- //
// ++ ACTION ++ //
public function AddSegment(string $fn,?TwigIface $oPrev=NULL) : TwigIface {
$oNew = new TwigClass($this,$fn,$oPrev);
if (is_null($oPrev)) {
$this->QOBase()->SetIt($oNew);
}
$this->QOLeaf()->SetIt($oNew);
return $oNew;
}
public function ParsePath(string $fpr) : TwigIface {
$fpClean = trim($fpr,'/'); // make sure there are no extra slashes
$arPath = explode('/',$fpClean);
$oSeg = NULL;
foreach ($arPath as $fnSeg) {
$oSeg = $this->AddSegment($fnSeg,$oSeg);
}
return $oSeg;
}
// -- ACTION -- //
}