Ferreteria/v0.6/clade/IO/Aspect/Connx/Stream/aux/Updater

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | IO‎ | Aspect‎ | Connx‎ | Stream
Jump to navigation Jump to search
clade: IO\Aspect\Connx\Stream\aux\Updater
Clade Family
Updater Updater (none)
Clade Aliases
Alias Clade
Base* Sys\Events\Updater
CableAdmin IO\Aspect\Connx\aux\Cable
StreamIface IO\Aspect\Connx\Stream
Subpages

About

  • Purpose: Sys\Events\Updater for Stream objects to use
    • It has a class-specific QObj-workalike: IO\Aspect\Connx\Stream\aux\Q\Updater

History

  • 2026-02-19 created
  • 2026-03-04 moved from Stream/Finite/Buffer/aux to Stream/aux, because it's really about any type of Stream

Code

as of 2026-03-04:

interface iUpdater extends BaseIface {
    static function FromStreams(StreamIface $oSrce, StreamIface $oDest) : self;
}
class cUpdater extends BaseClass implements iUpdater {

    // ++ SETUP ++ //

    public static function FromStreams(StreamIface $oSrce, StreamIface $oDest) : iUpdater {
        $oThis = new static;
        $oThis->WithStreams($oSrce,$oDest);
        return $oThis;
    }

    // ++ SETUP: dynamic ++ //

    private $oSrce;
    private $oDest;

    protected function WithStreams(StreamIface $oSrce, StreamIface $oDest) {
        $this->oSrce = $oSrce;
        $this->oDest = $oDest;
    }

    // -- SETUP -- //
    // ++ STATE ++ //

    private $sSfx = NULL;
    public function Suffix(?string $s) : string { return is_string($s) ? ($this->sSfx = $s) : $this->sSfx; }

    // -- STATE -- //
    // ++ EVENTS ++ //

    // CEMENT
    public function OnBefore() {   // called before starting OnChange() / OnCheck() loop
        $oPanel = CableAdmin::OPanel();
        $oPanel->OnBefore();
    }
    // CEMENT
    public function OnChange() {  // called every time something changed
        $oDest = $this->oDest;
        $sDest = number_format($oDest->NPushedBytes());
        $sMsg = $sDest.' bytes';
        $oPanel = CableAdmin::OPanel();
        $oPanel->Message($sMsg);
        $oPanel->OnChange();
    }
    // CEMENT
    public function OnCheck() {   // less-frequent checks that may take longer to do
        #$oPanel = CableAdmin::OPanel();
    }
    // CEMENT
    public function OnAfter() {   // called when there will be no more updates (so always update the display)
        $oPanel = CableAdmin::OPanel();
        $oPanel->OnAfter();
    }

    // -- EVENTS -- //

}