Ferreteria/v0.6/clade/Sys/FileSys/Node

From WoozleCodes
Jump to navigation Jump to search
clade: Sys\FileSys\Node
Clade Family
StandardBase Node

Fi
Fo

Clade Aliases
Alias Clade
FiNode* Sys\FileSys\Node\Fi
FoNode* Sys\FileSys\Node\Fo
Ident* Sys\FileSys\Aspect\Ident
InOut* Sys\FileSys\Aspect\InOut
Subpages

Functions

public

Code

interface iNode extends BaseIface {
    // SETUP
    static function FromSpec(string $fs) : self;
    static function FromSplInfo(SplFileInfo $on) : self;
    // ASPECTS
    function Ident(?IdentIface $o=NULL) : IdentIface;  // identifier, i.e. filespec
    function InOut(?InOutIface $o=NULL) : InOutIface;  // input/output, i.e. file access
}
abstract class caNode extends BaseClass implements iNode {

    // ++ CONFIG ++ //

    protected function InspectorClass() : string { return RowViewClass::class; }

    static protected function FiNodeClass() : string { return FiNodeClass::class; }
    static protected function FoNodeClass() : string { return FoNodeClass::class; }

    abstract protected function IdentClass() : string;
    abstract protected function InOutClass() : string;

    // -- CONFIG -- //
    // ++ SETUP ++ //

    protected function __construct(){}  // only construct via static pseudoconstructors

    // IFACE
    /* 2025-12-13 What was this even for?
    static public function FromRowData(RowDataIface $oa) : RowViewIface {
        $oThis = new static;
        $oThis->WithRowData($oa);
        return $oThis;
    }
    */

    static public function FromSpec(string $fs) : iNode {
        if (file_exists($fs)) {
            if (is_file($fs)) {
                $sc = static::FiNodeClass();
            } elseif (is_dir($fs)) {
                $sc = static::FoNodeClass();
            } else {
                echo self::CodingPrompt("Node type for [$fs] needs to be handled."); die();
            }
        } else {
            // Node not found; assume folder if there's an ending slash
            $isFldr = str_ends_with($fs,DIRECTORY_SEPARATOR);
            if ($isFldr) {
                $sc = static::FoNodeClass();
            } else {
                $sc = static::FiNodeClass();
            }
        }
        $oThis = new $sc;
        $oThis->WithSpec($fs);
        return $oThis;
    }
    static public function FromSplInfo(SplFileInfo $on) : iNode {
        if ($on->IsDir()) {
            $sc = static::FoNodeClass();
        } elseif ($on->IsFile()) {
            $sc = static::FiNodeClass();
        } else {
            $this->CodingPrompt('Not sure what conditions might cause this...');
        }
        $oThis = new $sc;
        $oThis->Ident()->OSpec()->SetIt($on->getPathname());
        return $oThis;
    }

    // ++ SETUP: dynamic ++ //

    protected function WithSpec(string $fs) : void {
        $this->Ident()->QSFullSpec()->SetIt($fs);
    }
    /* 2025-12-13 What was this even for?
    protected function WithRowData(RowDataIface $oa) : void {
        self::PromptForMethod();
    }
    */

    // -- SETUP -- //
    // ++ ASPECTS ++ //

    private $oID = NULL;
    public function Ident(?IdentIface $o=NULL) : IdentIface { return is_object($o) ? ($this->oID = $o) : ($this->oID ?? ($this->oID = $this->NewIdent())); }
    protected function NewIdent() : IdentIface { return ($this->IdentClass())::FromNode($this); }

    private $oIO = NULL;
    public function InOut(?InOutIface $o=NULL) : InOutIface { return is_object($o) ? ($this->oIO = $o) : ($this->oIO ?? ($this->oIO = $this->NewInOut())); }
    protected function NewInOut() : InOutIface { return ($this->InOutClass())::FromNode($this); }

    // -- ASPECTS -- //
}