Ferreteria/v0.6/clade/Aux/StandardBase/Objectory: Difference between revisions
< Ferreteria | v0.6 | clade | Aux/StandardBase
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{page/clade | {{page/clade/v2 | ||
|fam= | |||
! | {{!}} align=right {{!}} {{l/ver/clade|Aux|StandardBase}} | ||
{{!}} align=center {{!}} → {{l/ver/clade|Aux\StandardBase|Objectory}} → | |||
{{!}} align=left {{!}} | |||
{{l/ver/clade|Sys\Events|InputRq}}<br> | |||
{{l/ver/clade|Data\Base\Result|Player}} | |||
→ {{l/ver/clade|Sys\Events|InputRq}}<br> | }} | ||
==About== | |||
|} | '''Purpose''': a {{l/ver/topic|sys|Registry}} for global objects | ||
At startup, objects of this class or its podlings can self-register with <code>{{l/ver/fx|SignThisUp}}()</code>. This creates an array-entry keyed to [<code>{{l/ver/fx|ClassSlug}}()</code>]+[<code>{{l/ver/fx|ObjectSlug}}()</code>], with the object (<code>$this</code>) as the array entry's value. | |||
Code elsewhere can access registered objects via... {{hashtag|TODO}} | |||
==Code== | ==Code== | ||
''as of 2025-09- | ''as of 2025-09-29'' | ||
{{fmt/php/block|1= | {{fmt/php/block|1= | ||
interface | interface iObjectory extends BaseIface { | ||
// SETUP | // SETUP | ||
static function FromSlug(string $sSlug) : self; | static function FromSlug(string $sSlug) : self; // create a new object with a name-slug | ||
// SETTING | |||
function ObjectSlug() : string; | |||
} | } | ||
class | 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 | static protected function ClassSlug() : string { echo self::PromptForMethod('Must define ClassSlug() for this clade.').CRLF; die(); } | ||
// -- CONFIG -- // | // -- CONFIG -- // | ||
// ++ SETUP ++ // | // ++ SETUP ++ // | ||
protected function __construct(){} | |||
static public function FromSlug(string $sSlug) : iObjectory { ($oThis = new static)->WithSlug($sSlug); return $oThis; } | |||
private $sSlug; | private $sSlug; | ||
public function ObjectSlug() : string { return $this->sSlug; } | |||
// ++ SETUP: dynamic ++ // | // ++ SETUP: dynamic ++ // | ||
// Remember the slug, and self-register with it. | |||
protected function WithSlug(string $sSlug) { | protected function WithSlug(string $sSlug) { | ||
$this->sSlug = $sSlug; | $this->sSlug = $sSlug; | ||
$this-> | $this->SignThisUp(); | ||
} | } | ||
// -- SETUP -- // | // -- SETUP -- // | ||
// ++ REGISTRY ++ // | // ++ REGISTRY ++ // | ||
static private array $arObjRegs = []; | static private array $arObjRegs = []; | ||
static protected function Register() : RegIface { | static protected function Register() : RegIface { die('Use SignUpList()'); | ||
static protected function Classifest() : ArrayIface { // clade-specific manifest (sub-array) | |||
$sCSlug = static::ClassSlug(); | $sCSlug = static::ClassSlug(); | ||
if (array_key_exists($sCSlug,self::$arObjRegs)) { | if (array_key_exists($sCSlug,self::$arObjRegs)) { | ||
| Line 73: | Line 63: | ||
} | } | ||
protected function SelfRegister() { | protected function SelfRegister() { die('Use SignThisUp()'); } | ||
protected function SignThisUp() { | |||
$sSlug = $this->ObjectSlug(); | $sSlug = $this->ObjectSlug(); | ||
static:: | static::Classifest()->SetIt($sSlug,$this); | ||
} | } | ||
Latest revision as of 02:29, 16 October 2025
| ||||||||||||
About
Purpose: a Registry for global objects
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... #TODO
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 -- //
}