Ferreteria/v0.6/fx/GetQObj

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | fx
Jump to navigation Jump to search

About

Action: retrieves (by key) an element from an array, wrapped in a QVar

Usage

  • defined by: Sys\Data\Things\Array\QStor
  • definition: protected function GetQObj(int : QVarIface)

Status

  • 2025-10-28 I think this needs to create the QVar if it's not found? TODO

Code

type-checking version, as of 2025-10-28

protected function GetQObj(int|string $snKey) : QVarIface {
        $qElem = $this->ar[$snKey];
        if (is_a($qElem,QVarIface::class)) {
            return $qElem;
        } else {
            $sElem = self::DiagnoseValue($qElem);
            $this->AmHere(self::Screen()->ErrorIt('Internal Error')." retrieving QStor element [$snKey]: expecting QVar, got $sElem.");
            return $this->QStrClass::FromString($sElem);
        }
    }

non-type-checking version, as of 2025-10-28

protected function GetQObj(int|string $snKey) : QVarIface { return $this->ar[$snKey]; }

Removed

2025-10-29

Commented out on 2025-10-19:

// 2025-10-19 I think I need to get more strict around expectations of what has been stored.
    protected function GetQObj(int|string $snKey) : QVarIface { return static::ToQObj($this->ar[$snKey]); }

    // (2025-10-29: This is a helper function that was only used here.)
    static protected function ToQObj(QVarIface|string $vElem) : QVarIface {
        if (is_a($vElem,QVarIface::class)) {
            return $vElem;
        } elseif(is_string($vElem)) {
            $os = QStrClass::FromString($vElem);
            return $os;
        } else {
            // 2025-07-13 keeping this code in case we need to error-handle other types
            $sType = gettype($vElem);
            $this->AmHere("INTERNAL ERROR: storage element [$snKey] is type $sType; must be QVar object or string.");
            $this->RenderStackDump();
        }
    }