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

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Config
Jump to navigation Jump to search
clade: Config\Roster\for\AClass
Clade Family
(root) AClass [i,t]

Ops

About

Trait/interface to get a class included in the Class Registry. (Need to explain how this works...)

See also: AnObject - for getting an object included in the Object Registry.

Code

as of 2025-09-28

interface iAClass {
    // CONFIG
    static function ClassSlug() : string; // 2025-06-08 not sure this needs to be public
    // SETUP
    static function RegisterSelf() : void;
    static function FromClassSlug(string $sSlug) : QStrIface;
    static function AccessSelf() : self;
}
trait tAClass { // IMPLEMENTS iAClass
    // ++ SETUP ++ //

    public static function RegisterSelf() : void {
        static::ClassRoster()->SetIt(static::ClassSlug(),get_called_class());
    }
    public static function FromClassSlug(string $sSlug) : QStrIface {
        return static::ClassRoster()->QryIt($sSlug);
    }
    public static function AccessSelf() : iAClass {
        $sc = static::ClassRoster()->GetIt(static::ClassSlug());
        $oThis = new ($sc);
        return $oThis;
    }

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

    static private $oaClsRost=NULL;
    static public function ClassRoster() : RostIface { return self::$oaClsRost ?? (self::$oaClsRost = RostClass::AsNew()); }

    // -- OBJECT -- //
}