Ferreteria/v0.6/clade/Aux/StandardBase/Objectory: Difference between revisions

From Woozle Writes Code
Jump to navigation Jump to search
(updates)
No edit summary
Line 9: Line 9:
→ {{l/ver/clade|Data\Base\Result|Player}}
→ {{l/ver/clade|Data\Base\Result|Player}}
|}
|}
==About==
This is a way of maintaining a list of named objects that can be accessed globally.
At startup, objects of this class or its podlings can self-register with <code>SignThisUp()</code>. This creates an array-entry keyed to [<code>ClassSlug()</code>]+[<code>ObjectSlug()</code>], with the object (<code>$this</code>) as the array entry's value.
Code elsewhere can access registered objects via... [to be documented]
==Code==
==Code==
''as of 2025-09-29''
''as of 2025-09-29''

Revision as of 15:26, 29 September 2025

clade: Aux\StandardBase\Objectory
Clade Family
StandardBase Objectory

InputRq
Player

About

This is a way of maintaining a list of named objects that can be accessed globally.

At startup, objects of this class or its podlings can self-register with SignThisUp(). This creates an array-entry keyed to [ClassSlug()]+[ObjectSlug()], with the object ($this) as the array entry's value.

Code elsewhere can access registered objects via... [to be documented]

Code

as of 2025-09-29

interface iObjectory extends BaseIface {
    // SETUP
    static function FromSlug(string $sSlug) : self; // create a new object with a name-slug
    // SETTING
    function ObjectSlug() : string;
}
class cObjectory extends BaseClass implements iObjectory {

    static protected function RegisterClass() : string { return RegClass::class; }
    #static protected function ManifestClass() : string { return MfsClass::class; }

    static protected function ClassSlug() : string { echo self::PromptForMethod('Must define ClassSlug() for this clade.').CRLF; die(); }

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

    protected function __construct(){}
    static public function FromSlug(string $sSlug) : iObjectory { ($oThis = new static)->WithSlug($sSlug); return $oThis; }

    private $sSlug;
    public function ObjectSlug() : string { return $this->sSlug; }

    // ++ SETUP: dynamic ++ //

    // Remember the slug, and self-register with it.
    protected function WithSlug(string $sSlug) {
        $this->sSlug = $sSlug;
        $this->SignThisUp();
    }

    // -- SETUP -- //
    // ++ REGISTRY ++ //

    static private array $arObjRegs = [];
    static protected function Register() : RegIface { die('Use SignUpList()');
    static protected function Classifest() : ArrayIface { // clade-specific manifest (sub-array)
        $sCSlug = static::ClassSlug();
        if (array_key_exists($sCSlug,self::$arObjRegs)) {
            $oReg = self::$arObjRegs[$sCSlug];
        } else {
            $csReg = static::RegisterClass();
            $oReg = $csReg::AsNew();
            self::$arObjRegs[$sCSlug] = $oReg;
        }
        return $oReg;
    }

    protected function SelfRegister() { die('Use SignThisUp()'); }
    protected function SignThisUp() {
        $sSlug = $this->ObjectSlug();
        static::Classifest()->SetIt($sSlug,$this);
    }

    // -- REGISTRY -- //
}