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 16:23, 6 November 2025 by Woozle (talk | contribs)
(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 (none)
Clade Aliases
Alias Clade
Subpages

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

as of 2025-11-05 (obsolete v1)

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

}