Futilities/v0.6/clade/Apps/dba/InArgs/@current/2025/10/23

From WoozleCodes
Jump to navigation Jump to search

as of 2025-10-23

trait tInRqData { // for users of this format
    // ++ CONFIG ++ //

    // UNPROMPT for dba command (do not override in podlings)
    static protected function InputClass() : string { return cInRqData::class; }

    // -- CONFIG -- //
}
interface iInRqData extends BaseIface {
    // DATA
    function QDbConnSlug() : QStrIface;
    function QSchemaSlug() : QStrIface;
    function OkToReplace() : bool;
    // OBJECTS
    function QODbConn() : QObjIface;
    function QOSchema() : QObjIface;
}
class cInRqData extends BaseClass implements iInRqData {

    // ++ DATA ++ //

    public function QDbConnSlug() : QStrIface { return $this->FetchItQ(KioskEnum::VAL_CONN->value);  }
    public function QSchemaSlug() : QStrIface { return $this->FetchItQ(KioskEnum::VAL_SCHEMA->value); }

    public function OkToReplace() : bool {
        #$sName = 'xf.replace';
        $sName = KioskEnum::VAL_REPLACE->value;
        $obVal = $this->FetchItQ($sName);
        $bVal = $obVal->HasIt() ? $obVal->GetIt() : FALSE;
        return $bVal;
    }

    // -- DATA -- //
    // ++ OBJECTS ++ //

    private $oqDbConn=NULL;
    public function QODbConn() : QObjIface {
        $oo = $this->oqDbConn;
        if (is_object($oo)) {
            $bDoGet = !$oo->HasIt();
        } else {
            $qo = QObjClass::AsNew();
            $bDoGet = TRUE;
            $this->oqDbConn = $oo;
        }
        if ($bDoGet) {
          echo $this->ReflectThis()->Report();
            $qo->SetIt($this->ODbConn());
        }
        return $qo;
    }
    /*
    protected function NewDbConn() : DbConnIface {
        // TODO
    }
    */

    private $oqSchema=NULL;
    public function QOSchema() : QObjIface {
        $oo = $this->oqSchema;
        if (is_object($oo)) {
            $bDoGet = !$oo->HasIt();
        } else {
            $oo = QObjClass::AsNew();
            $bDoGet = TRUE;
            $this->oqSchema = $oo;
        }
        #$this->AmHere("bDoGet=[$bDoGet]");
        if ($bDoGet) {
            $os = $this->QSchemaSlug();    // Schema name-slug
            #$this->AmHere();
            if ($os->HasIt()) {
                $this->AmHere();
                $sSch = $os->GetIt();
                $oqDbConn = $this->QODbConn();
                if ($oqDbConn->HasIt()) {
                    $oDbConn = $oqDbConn->GetIt();
                    $oSch = $oDbConn->GetSchema($sSch);
                    $oo->SetIt($oSch);
                }
            } else {
                echo 'INPUT: '.$this->Inspect()->Render().CRLF;
            }
        }
        return $oo;
    }

    // -- OBJECTS -- //
    // ++ OUTPUT ++ //

    // OVERRIDE
    public function Debug_Render() : string {
        $ar = $this->GetVals();
        $nAr = count($ar);
        if ($nAr > 0) {
            if ($nAr > 1) {
                $sOut = $nAr.' input elements:'.CRLF;
            } else {
                $sOut = 'One input element: ';
            }
            foreach ($ar as $sKey => $sVal) {
                $sOut .= "[$sKey] => [$sVal]".CRLF;
            }
        } else {
            $sOut = 'No elements in input array.'.CRLF;
        }

        return $sOut;

    }

    // -- OUTPUT -- //
}