Ferreteria/v0.6/clade/IO/Aspect/Host/@code/cur/2026/06/11

From WoozleCodes
Jump to navigation Jump to search
2026/06/10 2026/06/11 2026/06/12
interface iHost extends BaseIface {
    // SETUP
    static function FromSpecs(string $sHost, ?int $nPort=NULL) : self;
    static function AsLocal(?int $nPort=NULL) : self;
    // ACCESS
    function QSAddr() : QStrIface;
    function QIPort() : QIntIface;
}
class cHost extends BaseClass implements iHost {

    // ++ CONFIG ++ //

    public function SType()             : string { return 'host address'; }

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

    protected function __construct(){}

    public static function FromSpecs(string $sAddr, ?int $nPort=NULL) : iHost {
        $oThis = new static;
        $oThis->WithSpecs($sAddr,$nPort);
        return $oThis;
    }
    public static function AsLocal(?int $nPort=NULL) : iHost {
        $oThis = new static;
        $oThis->WithSpecs('localhost',$nPort);
        return $oThis;
    }

    // ++ SETUP: dynamic ++ //

    protected function WithSpecs(string $sAddr, ?int $nPort) : void {
        $this->QSAddr()->SetIt($sAddr);
        $this->QIPort()->SetItNz($nPort);
    }

    // -- SETUP -- //
    // ++ ACCESS ++ //

    private $osAddr = NULL; public function QSAddr() : QStrIface { return $this->osAddr ?? ($this->osAddr = QStrClass::AsNew()); }
    private $oiPort = NULL; public function QIPort() : QIntIface { return $this->oiPort ?? ($this->oiPort = QIntClass::AsNew()); }

    // -- ACCESS -- //
    // ++ UI ++ //

    public function DescribeInline() : string {
        $oScrn = self::Screen();
        $sAddr = $this->QSAddr()->GetItNz($oScrn->FaintIt('(local)'));

        $oiPort = $this->QIPort();
        $sPort = $oiPort->HasIt() ? (':'.$oiPort->GetIt()) : '';
        return "$sAddr$sPort";
    }

    // -- UI -- //
}