Ferreteria/v0.6/clade/Config/Roster/for/AnObject

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Config
Jump to navigation Jump to search
clade: Config\Roster\for\AnObject
Clade Family
(root) AnObject [i,t] Conn
Clade Aliases
Alias Clade
Rost* [c,i] Objects
Subpages

History

Code

as of 2025-10-21

interface iAnObject {
    // SETTINGS
    function ObjectSlug() : string;
}
trait tAnObject { // IMPLEMENTS iAnObject

    // ++ CONFIG ++ //

    static protected function RosterClass() : string { return RostClass::class; }  // DEFAULT

    // -- CONFIG -- //
    // ++ SETUP: dynamic ++ //

    private $sOSlug;
    protected function WithSlug(string $sSlug) {  // TODO: maybe rename as WithObjectSlug(), or maybe change ObjectSlug to a QStr
        $this->sOSlug = $sSlug;
        $this->AmHere("REGISTERING SLUG [$sSlug] in ".static::ObjectRoster()->ObjectInfo());
        $this->RegisterThis();
    }
    public function ObjectSlug() : string { return $this->sOSlug; }
    private function RegisterThis() {
        $sOSlug = $this->ObjectSlug();
        $oRost = static::ObjectRoster();
        #$this->AmHere("REGISTERING OBJECT [$sOSlug] which is object of class ".get_called_class());
        $oRost->SetIt($sOSlug,$this);
        #echo $oRost->ReflectThis()->Report();
        $this->AmHere("Registered [$sOSlug](".$this->ObjectID().") in Roster:");

        $arVals = $oRost->GetVals();
        if (count($arVals) > 0) {
            foreach ($arVals as $sKey => $oItem) {
                echo " - [$sKey] => ".self::DiagnoseValue($oItem).CRLF;
            }
        } else {
            echo ' - NOTHING STORED!'.CRLF;
            echo $oRost->ReflectThis()->Report(); die();
        }

        //+DEBUG
        $os = $oRost->GetItQ($sOSlug);
        echo " - RETRIEVED VALUE of [$sOSlug]: "
          .($os->HasIt() ? self::DiagnoseValue($os->GetIt()) : '(EMPTY)').CRLF;
        //-DEBUG
    }

    // -- SETUP -- //
    // ++ OBJECT ++ //

    static private $oaObjRost=NULL;
    static public function ObjectRoster() : RostIface { return self::$oaObjRost ?? (self::$oaObjRost = (static::RosterClass())::AsNew()); }

    // -- OBJECT -- //
}