Ferreteria/v0.6/clade/Sys/FileSys/Node/inout/Fol/@code/cur/2026/08/20

From WoozleCodes
Jump to navigation Jump to search
2026/08/19 2026/08/20 2026/08/21
/* Base  [ca,i] */ use Woozalia\Ferret\Sys\FileSys\Node\aux\{ caAspect as BaseClass, iAspect as BaseIface };
/* NdTypeIface  */ use Woozalia\Ferret\Sys\FileSys\Node\xenum\iNodeType as NdTypeIface;
/* Node*  [c,i] */ use Woozalia\Ferret\Sys\FileSys\{ cNode as NodeClass, iNode as NodeIface };
/* Nodes* [c,i] */ #use Woozalia\Ferret\Sys\FileSys\Node\list\{ cNodes as NodesClass, iNodes as NodesIface };
/* DirIface   */ use Woozalia\Ferret\Sys\FileSys\Node\venue\iVenDir as DirIface;
/* SelfIface    */ use Woozalia\Ferret\Sys\FileSys\Node\inout\iFol as SelfIface;

interface iFol extends BaseIface {
    // I/O: read
    #var ?NodesIface $OANodes { get; }
    var DirIface $ODirList { get; }
    function NodeForEntry(string $fn, ?NdTypeIface $oType=NULL) : NodeIface;
    // I/O: write
    function MkDir(int $nPerms=0777) : bool;
}
class cFol extends BaseClass implements SelfIface {

    // ++ CONFIG ++ //

    public function SType() : string { return 'folder'; }
    public function IdentityForLog() : string { return $this->ObjectIDForLog().' '.$this->ONode->SUSpec; }

    // -- CONFIG -- //
    // ++ I/O: read ++ //

    public DirIface $ODirList { get => $this->ODirList ??= $this->ONode->OVenNode->ODirList; }


    // ++ I/O: write ++ //

    public function MkDir(int $nPerms=0777) : bool { return $this->ONode->OVenNode->MkDir($nPerms); }

    // -- ACCESS -- //
    // ++ FIGURING ++ //
/* 2026-07-23 basically an alias for what *was* called NewSubNode()
    public function NodeForEntry(string $fn, ?NdTypeIface $oType=NULL) : NodeIface {
        $oOuter = $this->ONode;
        $oInner = $oOuter->OFolOps->NewSubNode($fn,$oType);
        return $oInner;
    }
    #public function NewSubNode(string $fn, ?NdTypeIface $oType=NULL) : NodeIface {
    */
    // 2026-07-23 TODO: At present, $oType is never used. Fix or remove.
    public function NodeForEntry(string $fn, ?NdTypeIface $oType=NULL) : NodeIface {
        $oNodeOu = $this->ONode;          // outer Node
        $oVenConn = $oNodeOu->OVenConn;   // Venue Connx for this operation
        // calculate the USpec for the sub-node (there's probably a simpler way...)
        $oPSpecOu = $oNodeOu->OPSpec;
        // get new objects for the twig's Node, PSpec, and USpec
        $oPSpecIn = $oPSpecOu->AddNext($fn);
        $oNodeIn = NodeClass::FromOPSpec($oVenConn,$oPSpecIn);

        #$oUSpecIn = clone $oPSpecIn->OUSpec;
        // add the twig-name to the twig's PSpec
        // get the resulting PSpec string
        #$sPSpecIn = $oPSpecIn->SPathFull;
        // update the twig's USpec object
        #$oUSpecIn->SPSpec = $oPSpecIn->SPathFull;

        #$oNodeIn->SUSpec = $oUSpecIn->SUSpec; // set the twig's USpec
        #$oNodeIn->SPSpec = $sPSpecIn;
        // twig can point to the same Venue
        #$oNodeIn->OVenType = $oVenType;
        #$this->AmHere('Venue is '.get_class($this->OVenue));
        #$this->AmHere("NODE [$sPSTwig]");
        /* 2026-07-21 won't work anymore; need to see what errors we get.
        $oNdInfo = $oVenue->ONodeInfo($sPSTwig);
        if ($oNdInfo->Exists) {
            $isFolder = $oNdInfo->IsFolder;
            #$this->AmHere("NODE [$sPSTwig] is folder?[$isFolder]");
            // Save the sub-objects we created, since we have them:
            $onTwig->OIdent->OUSpec = $oUSTwig;
            $onTwig->OIdent->OPSpec = $oPSTwig;
        } else {
            if (is_object($oType)) {
                $onTwig->OType = $oType;
            } else {
                $this->ThrowHissy("We'll have to deal with this eventually, but a use-case would help.");
            }
        }
        */

        return $oNodeIn;  // return new inner Node
    }

    // -- FIGURING -- //

}