Ferreteria/v0.6/clade/Sys/FileSys/Aspect/Ident/stringer/Chain

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | FileSys‎ | Aspect‎ | Ident‎ | stringer
Revision as of 15:31, 5 November 2025 by Woozle (talk | contribs) (Created page with "{{page/clade/v2 |fam= {{!}} align=right {{!}} {{l/ver/clade|Data\Mem\QVar|Str}} {{!}} align=center {{!}} ⇒ {{l/ver/clade|Sys\FileSys\Aspect\Ident\stringer|Chain}} ⇒ {{!}} align=left {{!}} /Nested/<br> /Root/ |alia= {{!-!}} '''Base'''* [c,i] {{!!}} {{l/ver/clade/full|p=ferreteria|Data\Mem\QVar|Str}} {{!-!}} '''Cap'''* [c,i] {{!!}} {{l/ver/clade/full|p=ferreteria|Sys\FileSys\Aspect\Ident\stringer\Chain\Nested\Named|Cap}} {{!-!}} '''File'''* [c,i] {...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
clade: Sys\FileSys\Aspect\Ident\stringer\Chain
Clade Family
Str Chain

Nested
Root

Clade Aliases
Alias Clade
Base* [c,i] Data\Mem\QVar\Str
Cap* [c,i] Sys\FileSys\Aspect\Ident\stringer\Chain\Nested\Named\Cap
File* [c,i] Sys\FileSys\Node\Fi
Fldr* [c,i] Sys\FileSys\Node\Fo
Node* [c,i] Sys\FileSys\Node
QObj* [c,i] Data\Mem\QVar\Obj
SelfIface Sys\FileSys\Aspect\Ident\stringer\Chain
Subpages

Code

as of 2025-11-05

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 -- //

}