Ferreteria/v0.6/clade/Sys/FileSys/Node/inout/Fil/@code

From WoozleCodes
Jump to navigation Jump to search
Code Snapshots & Removals
/* Base* [ca,i] */ use Woozalia\Ferret\Sys\FileSys\Node\aux\{ caAspect as BaseClass, iAspect as BaseIface };
/* FiOps* [c,i] */ use Woozalia\Ferret\Sys\FileSys\Node\inout\{ cFil as FiOpsClass, iFil as FiOpsIface };
/* FoOps* [c,i] */ use Woozalia\Ferret\Sys\FileSys\Node\inout\{ cFol as FoOpsClass, iFol as FoOpsIface };
/* VeDirIface   */ use Woozalia\Ferret\Sys\FileSys\Node\venue\iVenDir as VeDirIface;
/* VeSpecIface  */ use Woozalia\Ferret\Sys\FileSys\Node\venue\iVenSpec as VeSpecIface;
/* SelfIface    */ use Woozalia\Ferret\Sys\FileSys\Node\venue\iVenNode as SelfIface;
/* StreamIface  */ use Woozalia\Ferret\Sys\InOut\Connx\iStream as StreamIface;

interface iVenNode extends BaseIface {
    // INFO
    var bool $Exists      { get; }
    var bool $IsReadable  { get; }
    var bool $IsWritable  { get; }
    var bool $IsCreatable { get; }
    var bool $IsFolder    { get; }
    var bool $IsFile      { get; }
    var bool $IsLink      { get; }
    var int  $NSize       { get; }
    var int  $NModTime    { get; set; }
    // INFO: objects
    var VeDirIface  $ODirList { get; }
    var VeSpecIface $OSpecOps { get; }
    var StreamIface $OStream  { get; }
    // I/O: write
    function Touch(int $nPerms=0777) : bool;
    function MkDir(int $nPerms=0777) : bool;
    function MkDirFor(int $nPerms) : bool;
}
abstract class caVenNode extends BaseClass implements SelfIface {

    // ++ CONFIG ++ //

    abstract protected string $SCDirOps { get; }
    abstract protected string $SCSpecOps { get; }

    // -- CONFIG -- //
    // ++ INFO: objects ++ //

    public VeSpecIface $OSpecOps { get => $this->OSpecOps ??= $this->NewSpecOps(); }
    protected function NewSpecOps() : VeSpecIface { return ($this->SCSpecOps)::FromNode($this->ONode); }
    public VeDirIface $ODirList { get => $this->ODirList ??= $this->NewDirList(); }
    protected function NewDirList() : VeDirIface { return ($this->SCDirOps)::FromNode($this->ONode); }

    /*
    public VeDirIface $ODirList {
        get {
          $this->AmHere('USPEC: '.$this->ONode->SUSpec);
          $this->AmHere('SPEC OPS: '.get_class($this->OSpecOps));
          $this->AmHere('CONN OPS: '.get_class($this->ONode->OVenConn->OConnOps));
          $this->AmHere('CONN VEN: '.get_class($this->ONode->OVenConn));
            $aNames = $this->OSpecOps->ASNames;
            foreach ($aNames as $sName) {

            }
        }
    }
    */

    // ++ INFO: internal ++ //

    protected string $SPSpec { get => $this->SPSpec ??= $this->ONode->OPSpec->SPathFull; }

    // -- INFO -- //
    // ++ WRITE ++ //

    public function MkDirFor(int $nPerms) : bool {
        $fs = $this->SPSpec;
        $fsPar = dirname($fs);  // spec to parent folder
        $oVePar = new static;
        $oVePar->SPSpec = $fsPar;
        if ($oVePar->Exists) {
            $ok = TRUE; // folder exists = created successfully (earlier)
        } else {
            $ok = $oVePar->MkDir($nPerms); // try to create it
        }
        return $ok;
    }
}