Ferreteria/v0.6/clade/Sys/Data/Engine/aux/ActionRq/Admin/ToDbConn: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{page/clade/v2 |fam= {{!}} align=right {{!}} {{l/ver/clade|Sys\Data\Engine\aux\ActionRq|Admin}} {{!}} align=center {{!}} → {{l/ver/clade|Sys\Data\Engine\aux\ActionRq\Admin|ToDbConn}} → {{!}} align=left {{!}} ''(TBD)'' |alia= {{!-!}} '''Base'''* [c,i] {{!!}} {{l/ver/clade/full|p=ferreteria|Sys\Data\Engine\aux\ActionRq|Admin}} }} ==About== * '''Parallel''': {{l/same|ToDbOper}} ==Status== * '''{{fmt/date|2025|10|25}}''' under construction") |
No edit summary |
||
| Line 10: | Line 10: | ||
}} | }} | ||
==About== | ==About== | ||
* '''Parallel''': {{l/same|ToDbOper}} | * '''Parallel''': <s>{{l/same|ToDbOper}}</s> Removed on 2025-10-26 | ||
==Status== | ==Status== | ||
* '''{{fmt/date|2025|10|25}}''' under construction | * '''{{fmt/date|2025|10|25}}''' under construction | ||
* '''{{fmt/date|2025|10|26}}''' complete-ish, but still refactoring because stuff doesn't work yet | |||
==Code== | |||
''as of 2025-10-26'' | |||
{{fmt/php/block|1= | |||
interface iToDbConn { | |||
// objects | |||
function QDbOper() : QDbOperIface; | |||
} | |||
trait tToDbConn /* implements iToDbConn */ { | |||
// ++ REGISTRY ++ // | |||
// SHORTCUT | |||
protected function DbasesOArray() : ObjListIface { return ConnAdmin::ObjectRoster(); } | |||
// -- REGISTRY -- // | |||
// ++ OBJECTS ++ / | |||
private $qoOper = NULL; | |||
public function QDbOper() : QDbOperIface { | |||
$qoOper = $this->qoOper; | |||
if (is_null($qoOper)) { | |||
$qoOper = QDbOperClass::AsNew(); | |||
$this->qoOper = $qoOper; | |||
} | |||
$qoConn = $this->QDbConn(); | |||
$ok = $qoConn->HasIt(); | |||
$qoOper->HowItWent()->SetOkay($ok); | |||
if ($ok) { | |||
$oConn = $qoConn->GetIt(); | |||
$oOper = $oConn->OOper(); | |||
$qoOper->SetIt($oOper); | |||
} | |||
return $qoOper; | |||
} | |||
private $qoConn = NULL; | |||
protected function QDbConn() : QDbConnIface { | |||
$qoConn = $this->qoConn; | |||
if (is_null($qoConn)) { | |||
$qoConn = QDbConnClass::AsNew(); | |||
$this->qoConn = $qoConn; | |||
} | |||
if ($qoConn->HasIt()) { | |||
$qoConn = $this->FetchDBConn(); | |||
$this->qoConn = $qoConn; | |||
} | |||
return $qoConn; | |||
} | |||
private $oDBC=NULL; | |||
protected function ODbConn(?ConnIface $o=NULL) : ConnIface { | |||
return is_object($o) ? ($this->oDBC = $o) : ($this->oDBC ?? ($this->oDBC = $this->NewDbConn())); | |||
} | |||
protected function FetchDbConn() : QDbConnIface { | |||
$oScrn = self::Screen(); | |||
$oItWent = $this->HowItWent(); | |||
$qoConn = QDbConnClass::AsNew(); | |||
$this->AmHere(); | |||
// STEP 1: retrieve the name for the requested DB (if any) | |||
$qsName = $this->OAThisInput()->QDbConnSlug(); | |||
$didFind = FALSE; | |||
if ($qsName->HasIt()) { | |||
$sName = $qsName->GetIt(); | |||
if ($sName !== '') { | |||
$didFind = TRUE; | |||
} | |||
} else { | |||
$oItWent->SetError($oItWent::N_ERR_DB_SLUG); | |||
$oItWent->AddMsgString(self::Screen()->ErrorIt('No DB connection-name specified.')); | |||
} | |||
if ($didFind) { | |||
// STEP 2: try to get the DB connection spec object for that name: | |||
$ftName = $oScrn->BoldIt($sName); | |||
$oItWent->AddMsgString($oScrn->GreenIt("Using")." DB connection [$ftName]."); | |||
$oaDBs = ConnBase::Registry(); | |||
$osDB = $oaDBs->QryIt($sName); | |||
if ($osDB->HasIt()) { | |||
$oDB = $osDB->GetIt(); | |||
$qoConn->SetIt($oDB); | |||
$oItWent->SetOkay(TRUE); | |||
} else { | |||
$noFind = TRUE; | |||
$oItWent->SetError($oItWent::N_ERR_DB_DEFN); | |||
$oItWent->AddMsgString($oScrn->ErrorIt('Input Error').": Could not find DB access specs for [$ftName]."); | |||
} | |||
} | |||
/* | |||
if ($noFind) { | |||
echo $oaDBs->ReflectThis()->Report(); | |||
echo 'Available:'.CRLF; | |||
echo $oaDBs->Debug()->Render(); | |||
die(); | |||
// TODO: better error-handling | |||
} | |||
*/ | |||
return $qoConn; | |||
} | |||
// -- OBJECTS -- / | |||
} | |||
}} | |||
===Removed=== | |||
===={{fmt/date|2025|10|26}}==== | |||
{{fmt/php/block|1= | |||
// ACTION: tries to retrieve the slug-requested DB Connection object from the db registry | |||
// 2025-10-26 old version | |||
protected function FetchDbConn() : QDbConnIface { | |||
$osDbSlug = $this->QDbConnSlug(); | |||
$doListFiles = FALSE; // flip this on if the user needs it | |||
$qoDB = QDbConnClass::AsNew(); | |||
if ($osDbSlug->HasIt()) { | |||
// Get DB Connection slug for UI display: | |||
$sDbSlug = $osDbSlug->GetIt(); | |||
// TODO: Look up the DB object (there IS code for this, somewhere...) | |||
$oaDBs = $this->DbasesOArray(); | |||
#echo 'oaDBs CLASS: '.get_class($oaDBs).CRLF; | |||
$qoDbConn = $oaDBs->QryIt($sDbSlug); | |||
if ($qoDbConn->HasIt()) { | |||
$oDbConn = $qoDbConn->GetIt(); | |||
$qoDB->SetIt($oDbOper); | |||
} | |||
} | |||
return $qoDB; | |||
} | |||
}} | |||
Revision as of 00:51, 27 October 2025
| ||||||||||||||
About
- Parallel:
ToDbOperRemoved on 2025-10-26
Status
- 2025-10-25 under construction
- 2025-10-26 complete-ish, but still refactoring because stuff doesn't work yet
Code
as of 2025-10-26
interface iToDbConn {
// objects
function QDbOper() : QDbOperIface;
}
trait tToDbConn /* implements iToDbConn */ {
// ++ REGISTRY ++ //
// SHORTCUT
protected function DbasesOArray() : ObjListIface { return ConnAdmin::ObjectRoster(); }
// -- REGISTRY -- //
// ++ OBJECTS ++ /
private $qoOper = NULL;
public function QDbOper() : QDbOperIface {
$qoOper = $this->qoOper;
if (is_null($qoOper)) {
$qoOper = QDbOperClass::AsNew();
$this->qoOper = $qoOper;
}
$qoConn = $this->QDbConn();
$ok = $qoConn->HasIt();
$qoOper->HowItWent()->SetOkay($ok);
if ($ok) {
$oConn = $qoConn->GetIt();
$oOper = $oConn->OOper();
$qoOper->SetIt($oOper);
}
return $qoOper;
}
private $qoConn = NULL;
protected function QDbConn() : QDbConnIface {
$qoConn = $this->qoConn;
if (is_null($qoConn)) {
$qoConn = QDbConnClass::AsNew();
$this->qoConn = $qoConn;
}
if ($qoConn->HasIt()) {
$qoConn = $this->FetchDBConn();
$this->qoConn = $qoConn;
}
return $qoConn;
}
private $oDBC=NULL;
protected function ODbConn(?ConnIface $o=NULL) : ConnIface {
return is_object($o) ? ($this->oDBC = $o) : ($this->oDBC ?? ($this->oDBC = $this->NewDbConn()));
}
protected function FetchDbConn() : QDbConnIface {
$oScrn = self::Screen();
$oItWent = $this->HowItWent();
$qoConn = QDbConnClass::AsNew();
$this->AmHere();
// STEP 1: retrieve the name for the requested DB (if any)
$qsName = $this->OAThisInput()->QDbConnSlug();
$didFind = FALSE;
if ($qsName->HasIt()) {
$sName = $qsName->GetIt();
if ($sName !== '') {
$didFind = TRUE;
}
} else {
$oItWent->SetError($oItWent::N_ERR_DB_SLUG);
$oItWent->AddMsgString(self::Screen()->ErrorIt('No DB connection-name specified.'));
}
if ($didFind) {
// STEP 2: try to get the DB connection spec object for that name:
$ftName = $oScrn->BoldIt($sName);
$oItWent->AddMsgString($oScrn->GreenIt("Using")." DB connection [$ftName].");
$oaDBs = ConnBase::Registry();
$osDB = $oaDBs->QryIt($sName);
if ($osDB->HasIt()) {
$oDB = $osDB->GetIt();
$qoConn->SetIt($oDB);
$oItWent->SetOkay(TRUE);
} else {
$noFind = TRUE;
$oItWent->SetError($oItWent::N_ERR_DB_DEFN);
$oItWent->AddMsgString($oScrn->ErrorIt('Input Error').": Could not find DB access specs for [$ftName].");
}
}
/*
if ($noFind) {
echo $oaDBs->ReflectThis()->Report();
echo 'Available:'.CRLF;
echo $oaDBs->Debug()->Render();
die();
// TODO: better error-handling
}
*/
return $qoConn;
}
// -- OBJECTS -- /
}
Removed
2025-10-26
// ACTION: tries to retrieve the slug-requested DB Connection object from the db registry
// 2025-10-26 old version
protected function FetchDbConn() : QDbConnIface {
$osDbSlug = $this->QDbConnSlug();
$doListFiles = FALSE; // flip this on if the user needs it
$qoDB = QDbConnClass::AsNew();
if ($osDbSlug->HasIt()) {
// Get DB Connection slug for UI display:
$sDbSlug = $osDbSlug->GetIt();
// TODO: Look up the DB object (there IS code for this, somewhere...)
$oaDBs = $this->DbasesOArray();
#echo 'oaDBs CLASS: '.get_class($oaDBs).CRLF;
$qoDbConn = $oaDBs->QryIt($sDbSlug);
if ($qoDbConn->HasIt()) {
$oDbConn = $qoDbConn->GetIt();
$qoDB->SetIt($oDbOper);
}
}
return $qoDB;
}