Ferreteria/v0.6/clade/Sys/FileSys/Aspect/Ident/stringer/Chain
Jump to navigation
Jump to search
| ||||||||||||||||||||
About
- PURPOSE: Ident (filespec) which breaks the spec up into objects, one per path-segment (Piece),
History
- 2023-11-03 moved from ...\File\caPathPiece -> ...\File\Path\caPiece
- 2024-12-24 moved from [WF]Data/Stored/File/Path -> [WF]IO/fsys/Path
- 2024-12-25 updated: "Spec" stuff is now in [WF]IO/fsys/Info/Node.php
- 2024-12-30 moved all Piece stuff ffom [WF]IO\fsys\Path -> [WF]Sys/FileSys
- 2024-12-31 ...and thence to [WF]Sys/FileSys/Aspect/Ident/stringer and renamed Piece -> Chain
- Chain now also descends from QStr.
- 2025-11-06 Starting over with new file. Reusing iface, but Chain is now a holder and not a QStr.
Code
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 -- //
}