Ferreteria/v0.6/clade/Sys/Data/Engine/aux/is/RqActor

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | Data‎ | Engine‎ | aux
Jump to navigation Jump to search
clade: Sys\Data\Engine\aux\is\RqActor
Clade Family
(root) RqActor

Admin
EngDbScList
→ [Fu]InReq

Clade Aliases
Alias Clade
ConnAdmin [ca] Conn
ActorRq* [i] ActionRq
QStr* [c,i] Str

Code

as of 2025-09-25

interface iRqActor {}
trait tRqActor {

    // ++ SETUP ++ //

    public static function FromRqActor(ActorRqIface $o) : self {
        $oThis = new static;
        $oThis->WithRqActor($o);
        return $oThis;
    }

    // ++ SETUP: dynamic ++ //

    protected function WithRqActor(RqActorIface $o) { $this->RqActor($o); }

    // -- SETUP -- //
    // ++ OBJECTS ++ //

    private $oRqAct=NULL;
    protected function ORqActor(?RqActorIface $o=NULL) : RqActorIface {
        return is_object($o) ? ($this->oRqAct = $o) : ($this->oRqAct ?? ($this->oRqAct = $this->NewRqActor()));
    }
    protected function NewRqActor() : RqActorIface {
        $oScrn = self::Screen();

        $oaIn = $this->OAUserInput();
        $osName = $oaIn->QDbConnSlug();
        #echo 'User Input: '.$oaIn->Debug_Render().CRLF;
        #echo 'oaCurr: '.$oaIn->ReflectThis()->Report();
        $didFind = FALSE;
        $didGive = $osName->HasIt();  // Did the user give a connection name?
        if ($didGive) {
            #$this->AmHere();
            $sName = $osName->GetIt();
            $ftName = $oScrn->BoldIt($sName);
            if ($sName !== '') {
                $didFind = TRUE;  // Connection name found!
            }
        }

        $oaDBs = ConnAdmin::ObjectRoster();

        if ($didFind) {
            echo $oScrn->GreenIt("Using")." DB connection [$ftName]...".CRLF;

            $osConn = $oaDBs->QryIt($sName);
            if ($osConn->HasIt()) {
                $oConn = $osConn->GetIt();
            } else {
                $didFind = FALSE; // Name given doesn't match what we have available.
                echo $oScrn->ErrorIt('Input Error').": Could not find dbconn specs-object for [$ftName].".CRLF;
            }
        } else {
            $this->AmHere('no specs found in '.get_called_class());
            // 2025-09-08 if we knew which direction, could say "to receive data" or "for data source".
            //  Also, this same prompt appears when we've only asked for a listing. It should probably say "you can also", in that case.
            //  TLDR: this prompt should probably be shown by the caller, not here.
            if ($didGive) {
                echo $oScrn->ErrorIt('Input Error').": Could not find specs for connection '$ftName'.".CRLF;
            } else {
                echo $oScrn->WarnIt('Input Prompt').": Specify a DB connection.".CRLF;
            }
        }
        if (!$didFind) {
            echo 'Available DB specs:'.CRLF;
            echo $oaDBs->Inspect()->Render();
            die();
            // TODO: better error-handling
        }
        #echo '$oConn is '.get_class($oConn).CRLF;
        #echo '$oConn->GetIt() is '.get_class($oConn->GetIt()).CRLF;
        // 2025-07-11 I don't know why the Conn object is being double-packed inside QObj objects ($osConn->GetIt()->GetIt()), here; TODO: FIXLATER
        // 2025-09-24 This will probably not be type-correct anymore.
        $oOper = $oConn->GetIt()->OOper();
        return $oOper;
    }

    // -- OBJECTS -- //
}