Ferreteria/v0.6/clade/IO/Aspect/Connx/Stream/Native

From Woozle Writes Code
Jump to navigation Jump to search
clade: IO\Aspect\Connx\Stream\Native
Clade Family
Stream Native
Clade Aliases
Alias Clade
Subpages

About

  • Purpose: a Stream that uses a Native stream-resource type

Code


as of 2026-04-06:

interface iNative extends BaseIface {
    // SETUP
    static function FromNative(mixed $r, string $sName) : self;
}
abstract class caNative extends BaseClass implements iNative {

    // ++ SETUP ++ //

    public static function FromNative(mixed $r, string $sName) : iNative {
        $oThis = new static($sName);
        $oThis->HardAssert(is_resource($r),'Parameter must be a resource; received '.self::DiagnoseValue($r));
        $oThis->QNative()->SetIt($r);
        return $oThis;
    }

    // -- SETUP -- //
    // ++ STATUS ++ //

    // CEMENT
    protected function IsEoS() : bool { return feof($this->RNative()); }

    // -- STATUS -- //
    // ++ ADMIN ++ //

    // DEFAULT
    public function HasMore() : bool { return !feof($this->RNative()); }

    // -- ADMIN -- //
    // ++ OBJECTS (ish) ++ //

    private $qrNat = NULL;
    protected function QNative() : QResIface { return $this->qrNat ?? ($this->qrNat = QResClass::AsNew()); }
    protected function RNative() : mixed {
        if (is_null($this->qrNat)) {
            $this->AmHere('resource holder not set!');
        }
        $r = $this->qrNat->GetIt();
        return $r;
    }

    // -- OBJECTS -- //
    // ++ DIAGS: output ++ //

    protected function DescribeEoS() : string {
        $qr = $this->QNative();
        return $qr->HasIt() ? ($this->IsEoS() ? 'Y' : 'n') : 'n/a';
    }

    // ++ DIAGS: access ++ //

    public function DEBUG_Resource() : mixed { return $this->RNative(); }
    protected function VIEW_ObjectInfo() : string {
        $sID = $this->ObjectID();
        $sType = $this->SType();
        $sRes = $this->QNative()->HasIt() ? ('r'.get_resource_id($this->RNative())) : 'rNA!';
        return "(id$sID $sRes) $sType";
    }

    // -- DIAGS -- //
}