Ferreteria/v0.6/clade/Sys/FileSys/Aspect/Ident/stringer/Chain
Jump to navigation
Jump to search
| ||||||||||||||||||||||||||
Code
interface iChain extends BaseIface {
function AddSegment(string $fn) : CapIface;
function ParsePath(string $fpr) : CapIface;
function QOBase() : QObjIface;
}
abstract class caChain extends BaseClass implements SelfIface {
// ++ ACTION ++ //
public function AddSegment(string $fn) : CapIface { return new CapClass($fn,$this); }
// ACTION: Parse the given relative path and return a new PathPiece for the last segment
public function ParsePath(string $fpr) : CapIface {
$fpClean = trim($fpr,'/'); // make sure there are no extra slashes
$arPath = explode('/',$fpClean);
$oSeg = $this;
foreach ($arPath as $fnSeg) {
$oSeg = $oSeg->AddSegment($fnSeg);
}
return $oSeg;
}
// -- ACTION -- //
// ++ FIGURING ++ //
/* 2025-11-04 Removing these (for now) because of ambiguity with QSPath().
// RETURNS entire filespec, including base
public function GetSpec() : string { return $this->PathStatus()->GetAbsPath(); }
/*----
RETURNS relative filespec from base
PUBLIC because sometimes we need that information
* /
public function GetPath() : string { return $this->PathStatus()->GetRelPath(); }
*/
/**
* INPUT:
* $fsa = absolute filespec within this repository's folder
* NOTE: This functionality is basically tFolder::WhatRemains().
* Possibly that should be used instead of re-implementing here.
* HISTORY:
* 2023-12-05 moved from .\Kiosk\cRepository to .\Data\Stored\File\Path\caPiece
*/
public function FigureRelative(string $fsFull) : string {
// might as well do a sanity-check, even though it should already have been done
$fpThis = $this->PathStatus()->GetAbsPath();
// if $fsFull starts with the repo's base path...
if (str_starts_with($fsFull,$fpThis)) {
// get the part of $fsFull *after* that base path
$nlThis = strlen($fpThis);
$fpRemain = substr($fsFull,$nlThis);
} else {
// I think this still shouldn't happen...
echo "NO MATCH: FULL=[$fsFull], THIS=[$fpThis]<br>";
throw new \exception('Internal error: bad value in constructor');
}
return $fpRemain;
}
// -- FIGURING -- //
// ++ OBJECTS ++ //
private $qoBase = NULL;
public function QOBase() : QObjIface { return $this->qoBase ?? ($this->qoBase = QObjClass::AsNew()); }
// ++ OBJECTS: FILESYS ++ //
/**
* NOTE:
* 2023-10-03 These used to return different classes (cFile and cFolder),
* but apparently the functionality we need is now in a class which
* doesn't differentiate like that. (Maybe that's work to be done yet?)
*/
public function GetFileNode() : FileIface {
$fs = $this->GetSpec();
return new FileClass($fs);
}
public function GetFolderNode() : FolderIface {
$fs = $this->GetSpec();
return new FolderClass($fs);
}
public function Info() : NodeIface { return new NodeClass($this->GetSpec()); }
// -- OBJECTS -- //
}