Ferreteria/v0.5/registry/table

From Woozle Writes Code
< Ferreteria‎ | v0.5‎ | registry
Revision as of 13:34, 8 March 2022 by htyp>Woozle (Created page with "Table registration is a multi-stage process intended to minimize loading of unnecessary code while keeping configurability as flexible as possible. ==Table Spec registration==...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Table registration is a multi-stage process intended to minimize loading of unnecessary code while keeping configurability as flexible as possible.

Table Spec registration

Table registration for the Template:L/version Feature in /config/portable/tables-user.php:

class csTableSpecs extends FC\csaTableSpecs {
  
[ constants omitted ]

    static protected function DefaultDatabaseSlug() : string { return 'users'; }
   
    static public function OnSetup() {
        echo 'SETUP: '.__CLASS__.'<br>';
        self::Add1KeyTable  (self::KS_ACCT, ['sql'=>'user_account'  ,'aslug'=>'uacct']);
        self::AddXrefTable  (self::KS_AXG,  ['sql'=>'uacct_x_ugroup']);
        self::Add1KeyTable  (self::KS_CLI,  ['sql'=>'user_client'   ,'aslug'=>'ucli']);
        self::Add1KeyTable  (self::KS_GROUP,['sql'=>'user_group'    ,'aslug'=>'ugrp']);
        self::AddXrefTable  (self::KS_GXP,  ['sql'=>'ugroup_x_upermit']);
        self::Add1KeyTable  (self::KS_PERM, ['sql'=>'user_permit'   ,'aslug'=>'uperm']);
        self::Add1KeyTable  (self::KS_SESS, ['sql'=>'user_session'  ,'aslug'=>'usess']);
        self::Add1KeyTable  (self::KS_TOK,  ['sql'=>'user_token']);
        self::AddQuery      (self::KS_Q, []);
    }
    
    static public function Account()        : FDS\cTable { return F\data\csStocker::GetTableSpec(self::KS_ACCT); }
    static public function AccountXGroup()  : FDS\cTable { return F\data\csStocker::GetTableSpec(self::KS_AXG); }
    static public function Group()          : FDS\cTable { return F\data\csStocker::GetTableSpec(self::KS_GROUP); }
    static public function GroupXPermit()   : FDS\cTable { return F\data\csStocker::GetTableSpec(self::KS_GXP); }
    static public function Permit()         : FDS\cTable { return F\data\csStocker::GetTableSpec(self::KS_PERM); }
    static public function Session()        : FDS\cTable { return F\data\csStocker::GetTableSpec(self::KS_SESS); }
    static public function Tokens()         : FDS\cTable { return F\data\csStocker::GetTableSpec(self::KS_TOK); }
}

Table registration services

Table registration services in /config/portable/defaults.php:

abstract class csaTableSpecs {
    static abstract protected function DefaultDatabaseSlug() : string;
    
    static protected function Add1KeyTable(string $sSlug, array $arSpec) {
        $arSpec['.'] = $sSlug;
        $arSpec['key'] ='ID';
        $arSpec['db'] = static::DefaultDatabaseSlug();
        $oSpec = new FDS\cTableK1I($arSpec);
        FD\cTabloid::ObjectRegistry()->AddItem($sSlug, $oSpec);
    }
    static protected function AddXrefTable(string $sSlug, array $arSpec) {
        $arSpec['.'] = $sSlug;
        $arSpec['db'] = static::DefaultDatabaseSlug();
        $oSpec = new FDS\cTable($arSpec);
        FD\cTabloid::ObjectRegistry()->AddItem($sSlug, $oSpec);
    }
    static protected function AddQuery(string $sSlug, array $arSpec) {
        $arSpec['.'] = $sSlug;
        $arSpec['db'] = static::DefaultDatabaseSlug();
        $oSpec = new FDS\cQuery($arSpec);
        FD\cTabloid::ObjectRegistry()->AddItem($sSlug, $oSpec);
    }
}