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

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | FileSys
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

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

Code

as of 2025-08-10

class cNode extends BaseClass implements iNode {
    use RowViewTrait;

    // ++ CONFIG ++ //

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

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

    protected function IdentClass() : string { return IdentClass::class; }
    protected function InOutClass() : string { return InOutClass::class; }

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

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

    // IFACE
    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,self::Settings()::FILE_PATH_SEP);
            if ($isFldr) {
                $sc = static::FoNodeClass();
            } else {
                $sc = static::FiNodeClass();
            }
        }
        $oThis = new $sc;
        $oThis->WithSpec($fs);
        return $oThis;
    }
    static public function FromSplInfo(SplFileInfo $on) : iNode {
        $oThis = new static;
        $oThis->Ident()->QSFullSpec()->SetIt($on->getPathname());
        return $oThis;
    }

    // ++ SETUP: dynamic ++ //

    protected function WithSpec(string $fs) : void {
        $this->Ident()->QSFullSpec()->SetIt($fs);
    }
    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 -- //
}