Ferreteria/v0.6/clade/Sys/Events/InputRq: Difference between revisions

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Sys‎ | Events
Jump to navigation Jump to search
No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{page/clade}}
{{page/clade/v2
{| style="border: solid 1px black; float: right;"
|fam=
! colspan=3 | Clade Family
{{!}} align=right  {{!}} {{l/ver/clade|Sys\Events\has|ItWent}}[i,t]
|-
{{!}} align=center {{!}} &rarr; {{l/ver/clade|Sys\Events|InputRq}} &rarr;
| align=right |  
{{!}} align=left  {{!}} {{l/ver/clade|Sys\Events\InputRq|Setting}}
{{l/ver/clade|Aux\StandardBase|Objectorium}}(c)<br>
 
{{l/ver/clade|Sys\Events\has|ItWent}}(i,t)
|alia=
| &rarr; '''InputRq'''
{{!-!}} '''Base'''*      [c,i] {{!!}} {{l/ver/clade/full|Aux|StandardBase}}
| &rarr; {{l/ver/clade|Sys\Events\InputRq|Settable}}
{{!-!}} '''HasStatus'''* [i,t] {{!!}} {{l/ver/clade/full|Sys\Events\has|ItWent}}
{{!-!}} '''InData'''*    [c,i] {{!!}} {{l/ver/clade/full|Sys\Events\InputRq\aux|InRqData}}
{{!-!}} '''ItemIface'''        {{!!}} {{l/ver/clade/full|Sys\Events|InputItem}}
{{!-!}} '''PieceIface'''      {{!!}} {{l/ver/clade/full|Sys\Data\Things\Array\aux|Piece}}
{{!-!}} '''SelfIface'''        {{!!}} {{l/ver/clade/full|Sys\Events|InputRq}}
 
}}
==About==
* '''Purpose''': set of action-classes for handling user input parameters as a sequence of actions
**  These can then be described, acted on, or both.
* '''Note''': Not to be confused with:
** <code>[[../Action/]]</code>: the generic action-result base clades
** <code>{{l/ver/clade/full|Sys\Data\reqs\Engine|CommRq}}</code> - Database communication (data-xfer) requests
** <code>{{l/ver/clade/full|Sys\Data\reqs\Engine|AdminRq}}</code> - Database administration requests
==System==
This is part of the system whereby CLI input is parsed into future actions (`caActor` podlings), which at go-time are converted into fully-provisioned requests (e.g. <code>{{l/ver/clade/full|Sys\Data\reqs\Engine|AdminRq}}</code> podlings).
==History==
* '''{{fmt/date|2024|10|27}}''' (re?)started -- I have a distinct memory of writing somethng like this only a few weeks ago, but I cannot find it anywhere.
* '''{{fmt/date|2024|11|19}}''' renamed/moved from <code>{{l/ver/clade/full|Sys\Routing|Action}}</code> &rArr; <code>{{l/ver/clade/full|Sys\Events|Actor}}</code>.
* '''{{fmt/date|2025|01|22}}''' I tried to both rename this clade ''and'' combine it with the AdminRq/CommRq clades, but the combining part didn't work out.
** It still needs renaming, though -- so trying the less ambitious measure of renaming Actor -> InputRq.
* '''{{fmt/date|2025|09|27}}''' added <code>{{l/ver/clade/full|Config\Roster\for|AnObject}}</code> as trait to provide <code>{{l/ver/fx|WithSlug}}()</code> function, but this is really more of a guess than a "yes, this is appropriate".
==Thinking==
* '''{{fmt/date|2024|10|27}}''' Since I remember writing this but can't find it, I have to wonder if I did write it and then decide it was redundant.
** One reason I might have decided it's redundant is: instead of creating an object for each action parsed out of the input, why not just Do The Thing? Being able to handle the action-plan in different ways, though, is much easier if you're not dealing with that fork at the same time as you're parsing them out of the input. It's easier to juggle ten plates if you do them five at a time.
** ({{fmt/date|2024|12|15}}) I think the final deciding factor was that we don't have all the pieces we need when the Actor is created at parse-time -- the database object only becomes available sometime ''after'' the command is parsed. So we need an object that can remember what to do without having to do it right away.
==Functions==
{| class="wikitable sortable"
! name || type || notes
{{!-!}} <code>{{l/ver/fx|Describe}}()</code>        || abstract public || usually defined at the application-input level (e.g. <code>{{l/ver/clade|p=futilities|Sys\dba\InReq|DoExport}}</code>)
{{!-!}} <code>{{l/ver/fx|ParseInputArgs}}()</code>  || abstract protected ||
* typically defined at the application level (e.g. <code>{{l/ver/clade|p=futilities|Sys\dba|InReq}}</code>)
* also defined by {{l/ver/clade|Sys\Events\InputRq|Setting}} for inputs that map directly to value-names
{{!-!}} <code>{{l/ver/fx|ParseInputString}}()</code> || abstract protected ||
* typically defined at the application level (e.g. <code>{{l/ver/clade|p=futilities|Sys\dba|InReq}}</code>)
* also defined by <code>{{l/ver/clade|Sys\Events\InputRq|Setting}}</code> for inputs that map directly to value-names
{{!-!}} <code>{{l/sub/fx|WithItemPiece}}()</code>    || protected || calls <code>$this->{{l/ver/fx|ParseInputArgs}}()</code>, <code>$this->{{l/ver/fx|ParseInputString}}()</code>
|}
|}
==Aliases Used==
==Code==
* '''InDataIface''' = {{l/ver/clade|Sys\Events\InputRq\aux|InRqData}}
* '''Repository''': [https://gitlab.com/woozalia/ferreteria/-/blob/v0.6-dev/src/Sys/Events/InputRq.php v0.6-dev]
* '''ItemIface''' = {{l/ver/clade|Sys\Events|InputItem}}
* '''[[/@removed/]]'''
* '''PieceIface''' = {{l/ver/clade|Sys\Data\Things\Array\aux|Piece}}
* ''as of {{fmt/date|2025|11|19}}:''
{{fmt/php/block|1=
interface iInputRq extends BaseIface, HasStatusIface {
    // CONFIG
    function NameOfInput() : string;
    // SETUP
    function Item(ItemIface $o=NULL) : ItemIface;
    // ACTION
    function Go();
    // INFO
    function Describe() : string;
}
abstract class caInputRq extends BaseClass implements SelfIface {
    use HasStatusTrait;
 
    // ++ CONFIG ++ //
 
    // OVERRIDE
    protected function QVarClass(int{{!}}string $snKey) : string { return InDataClass::class; }
    // This tells the clade where to store the Singleton object for this podling-class-family.
    static protected function InputClass() : string { die(self::PromptForMethod('Define this in the root InputRq for the command.')); } // DEFAULT
    public function NameOfInput() : string { return $this->Item()->SName(); }
 
    // -- CONFIG -- //
    // ++ SETUP ++ //
 
    protected function __construct(){}


==Functions==
    static public function FromItemPiece(ItemIface $oItem, PieceIface $oPiece) : SelfIface {
===public===
        $oThis = new static;
* SETUP
        $oThis->WithItemPiece($oItem,$oPiece);
** {{fmt/php/inline|1=function Item(ItemIface $o=NULL) : ItemIface}}
        return $oThis;
** {{fmt/php/inline|static public function FromItemPiece(ItemIface $oItem, PieceIface $oPiece) : SelfIface}}
    }
* ACTION
 
** {{fmt/php/inline|function Go()}}
    // ++ SETUP: dynamic ++ //
* INFO
 
** {{fmt/php/inline|function Describe() : string}}
    // DOCS: https://wooz.dev/Ferreteria/v0.6/fx/WithItemPiece
===internal===
    protected function WithItemPiece(ItemIface $oItem, PieceIface $oPiece) : void {
* CONFIG
        $this->Item($oItem);
** {{fmt/php/inline|static protected function ClassSlug() : string { return 'in.req'; }}}: tells the Registry where to store the Singleton object for this podling-clade
        if ($oPiece->HasValue()) {
** {{fmt/php/inline|static protected function InputClass() : string}}: coding prompt
            $sVal = $oPiece->Value();
* SETUP
            $this->ParseInputArgs($oPiece->GetExtras());
** {{fmt/php/inline|protected function __construct(){}}}
        } else {
* SETUP: dynamic
            // check for default (used if request is present but with no value):
** {{fmt/php/inline|protected function WithItemValue(ItemIface $oItem, string $sValue) : void}}
            $osDef = $oItem->SDefault(); // TODO: Implement as $this->Attrs()->QryIt('valdef');
** {{fmt/php/inline|protected function WithItemPiece(ItemIface $oItem, PieceIface $oPiece) : void}}
            if ($osDef->HasIt()) {
* DATA
                $sVal = $osDef->GetIt();
** {{fmt/php/inline|1=protected function OAUserInput() : InDataIface { return $this->oInThis ?? ($this->oInThis = $this->NewUserInput()); }}}
            } else {
** {{fmt/php/inline|protected function NewUserInput() : InDataIface}}
                $sVal = '';
** {{fmt/php/inline|abstract protected function ParseInputString(string $s) : void;}}
            }
** {{fmt/php/inline|abstract protected function ParseInputArgs(array $ar);}}
        }
        $this->ParseInputString($sVal);
    }
 
    // NOTE: Basically identical to Events/Actor/Option::Item()
    private $oItem = NULL;
    public function Item(ItemIface $o=NULL) : ItemIface {
        if (is_object($o)) {
            self::HardAssert(is_null($this->oItem),'changing the item-object on an already-configured Action (should probably never happen)');
            // If we ever *actually* need to do this, we need to un-register and re-register.
            $this->oItem = $o;
        } else {
            $o = $this->oItem;  // return previously-set object
        }
        return $o;
    }
 
    // -- SETUP -- //
    // ++ DATA ++ //
 
    static private $oaInThis = NULL;
    protected function OAUserInput() : InDataIface { return self::$oaInThis ?? (self::$oaInThis = $this->NewUserInput()); }
    protected function NewUserInput() : InDataIface {
        $oa = (static::InputClass())::AsNew();
        return $oa;
    }
 
    abstract protected function ParseInputString(string $s) : void;
    abstract protected function ParseInputArgs(array $ar);
 
    // -- DATA -- //
}
}}

Latest revision as of 14:34, 19 November 2025

clade: Sys\Events\InputRq
Clade Family
ItWent[i,t] InputRq Setting
Clade Aliases
Alias Clade
Base* [c,i] Aux\StandardBase
HasStatus* [i,t] Sys\Events\has\ItWent
InData* [c,i] Sys\Events\InputRq\aux\InRqData
ItemIface Sys\Events\InputItem
PieceIface Sys\Data\Things\Array\aux\Piece
SelfIface Sys\Events\InputRq
Subpages

About

  • Purpose: set of action-classes for handling user input parameters as a sequence of actions
    • These can then be described, acted on, or both.
  • Note: Not to be confused with:
    • Action: the generic action-result base clades
    • Sys\Data\reqs\Engine\CommRq - Database communication (data-xfer) requests
    • Sys\Data\reqs\Engine\AdminRq - Database administration requests

System

This is part of the system whereby CLI input is parsed into future actions (`caActor` podlings), which at go-time are converted into fully-provisioned requests (e.g. Sys\Data\reqs\Engine\AdminRq podlings).

History

  • 2024-10-27 (re?)started -- I have a distinct memory of writing somethng like this only a few weeks ago, but I cannot find it anywhere.
  • 2024-11-19 renamed/moved from Sys\Routing\ActionSys\Events\Actor.
  • 2025-01-22 I tried to both rename this clade and combine it with the AdminRq/CommRq clades, but the combining part didn't work out.
    • It still needs renaming, though -- so trying the less ambitious measure of renaming Actor -> InputRq.
  • 2025-09-27 added Config\Roster\for\AnObject as trait to provide WithSlug() function, but this is really more of a guess than a "yes, this is appropriate".

Thinking

  • 2024-10-27 Since I remember writing this but can't find it, I have to wonder if I did write it and then decide it was redundant.
    • One reason I might have decided it's redundant is: instead of creating an object for each action parsed out of the input, why not just Do The Thing? Being able to handle the action-plan in different ways, though, is much easier if you're not dealing with that fork at the same time as you're parsing them out of the input. It's easier to juggle ten plates if you do them five at a time.
    • (2024-12-15) I think the final deciding factor was that we don't have all the pieces we need when the Actor is created at parse-time -- the database object only becomes available sometime after the command is parsed. So we need an object that can remember what to do without having to do it right away.

Functions

name type notes
Describe() abstract public usually defined at the application-input level (e.g. DoExport)
ParseInputArgs() abstract protected
  • typically defined at the application level (e.g. InReq)
  • also defined by Setting for inputs that map directly to value-names
ParseInputString() abstract protected
  • typically defined at the application level (e.g. InReq)
  • also defined by Setting for inputs that map directly to value-names
WithItemPiece() protected calls $this->ParseInputArgs(), $this->ParseInputString()

Code

interface iInputRq extends BaseIface, HasStatusIface {
    // CONFIG
    function NameOfInput() : string;
    // SETUP
    function Item(ItemIface $o=NULL) : ItemIface;
    // ACTION
    function Go();
    // INFO
    function Describe() : string;
}
abstract class caInputRq extends BaseClass implements SelfIface {
    use HasStatusTrait;

    // ++ CONFIG ++ //

    // OVERRIDE
    protected function QVarClass(int|string $snKey) : string { return InDataClass::class; }
    // This tells the clade where to store the Singleton object for this podling-class-family.
    static protected function InputClass() : string { die(self::PromptForMethod('Define this in the root InputRq for the command.')); } // DEFAULT
    public function NameOfInput() : string { return $this->Item()->SName(); }

    // -- CONFIG -- //
    // ++ SETUP ++ //

    protected function __construct(){}

    static public function FromItemPiece(ItemIface $oItem, PieceIface $oPiece) : SelfIface {
        $oThis = new static;
        $oThis->WithItemPiece($oItem,$oPiece);
        return $oThis;
    }

    // ++ SETUP: dynamic ++ //

    // DOCS: https://wooz.dev/Ferreteria/v0.6/fx/WithItemPiece
    protected function WithItemPiece(ItemIface $oItem, PieceIface $oPiece) : void {
        $this->Item($oItem);
        if ($oPiece->HasValue()) {
            $sVal = $oPiece->Value();
            $this->ParseInputArgs($oPiece->GetExtras());
        } else {
            // check for default (used if request is present but with no value):
            $osDef = $oItem->SDefault(); // TODO: Implement as $this->Attrs()->QryIt('valdef');
            if ($osDef->HasIt()) {
                $sVal = $osDef->GetIt();
            } else {
                $sVal = '';
            }
        }
        $this->ParseInputString($sVal);
    }

    // NOTE: Basically identical to Events/Actor/Option::Item()
    private $oItem = NULL;
    public function Item(ItemIface $o=NULL) : ItemIface {
        if (is_object($o)) {
            self::HardAssert(is_null($this->oItem),'changing the item-object on an already-configured Action (should probably never happen)');
            // If we ever *actually* need to do this, we need to un-register and re-register.
            $this->oItem = $o;
        } else {
            $o = $this->oItem;  // return previously-set object
        }
        return $o;
    }

    // -- SETUP -- //
    // ++ DATA ++ //

    static private $oaInThis = NULL;
    protected function OAUserInput() : InDataIface { return self::$oaInThis ?? (self::$oaInThis = $this->NewUserInput()); }
    protected function NewUserInput() : InDataIface {
        $oa = (static::InputClass())::AsNew();
        return $oa;
    }

    abstract protected function ParseInputString(string $s) : void;
    abstract protected function ParseInputArgs(array $ar);

    // -- DATA -- //
}