Ferreteria/v0.5/registry/table: Difference between revisions

From Woozle Writes Code
Jump to navigation Jump to search
(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==...")
 
m (2 revisions imported: moving this project here)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Table registration is a multi-stage process intended to minimize loading of unnecessary code while keeping configurability as flexible as possible.
Table registration is a multi-stage process intended to minimize loading of unnecessary code while keeping configurability as flexible as possible.
==Table Spec registration==
==Code==
Table registration for the {{l/version|login}} Feature in /config/portable/tables-user.php:
* {{l/ferreteria/code|config/portable/tables-user.php}} - example of Table Spec registration for the {{l/ver|login}} Feature
<syntaxhighlight lang=php>
* {{l/ferreteria/code|data/db/table/spec.php}} - Table Spec classes, and trait for Table registration
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); }
}
</syntaxhighlight>
==Table registration services==
Table registration services in /config/portable/defaults.php:
<syntaxhighlight lang=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);
    }
}
</syntaxhighlight>

Latest revision as of 16:45, 22 May 2022

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

Code