Ferreteria/v0.6/clade/Data/Mem/QVar/Str

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | Data‎ | Mem‎ | QVar
Jump to navigation Jump to search
clade: Data\Mem\QVar\Str
Clade Family
QVar Str

Strict
Tuple

Clade Aliases
Alias Clade
Base* [ca,i] Data\Mem\QVar
TypesStatic [cs] Data\Mem\Val\Types
Subpages

Usage

Ferreteria standard aliasing:

use Woozalia\Ferret\Data\Mem\QVar\cStr as QStrClass;
use Woozalia\Ferret\Data\Mem\QVar\iStr as QStrIface;

History

  • 2024-12-03 Finally changed my mind (again) and decided it's ok to have sensible defaults in the constructor.
    • Just don't let it get too complicated by trying to accommodate too many possible cases; that's what From*() pseudoconstructors are for.
    • No need for With*() methods because they'd just be SetIt() / SetItNz().

Code

interface iStr extends BaseIface {
    // SETUP
    static function FromString(string $s) : self;
    static function FromNzString(?string $s = NULL) : self;
    // ACCESS
    function SetIt(string $s);
    function SetItNz(?string $v);
    function &GetIt() : string;
    function GetItNz(string $sDefault='') : string;
    function RefIt(string &$v) : void;

    function CopyIt(BaseIface $os);
}

class cStr extends BaseClass implements iStr {

    // ++ SETUP ++ //

    public function __construct(string $s = NULL)  { $this->SetItNz($s); }

    static public function FromString(string $s) : iStr {
        $oThis = new static;
        $oThis->SetIt($s);
        return $oThis;
    }
    static public function FromNzString(?string $s = NULL) : iStr {
        return is_null($s) ? static::AsNew() : static::FromString($s);
    }

    public function CopyIt(BaseIface $os) { if ($os->HasIt()) $this->SetIt((string)$os->GetIt()); }

    // -- SETUP -- //
    // ++ ACCESS ++ //

    public function HasIt() : bool      { return $this->HasStr(); }
    public function SetIt(string $s)    { $this->SetStr($s); }
    public function SetItNz(?string $s) { $this->SetStrNz($s); }
    public function &GetIt() : string   { return $this->GetStr(); }
    public function GetItNz(string $sDef='',string $sPfx='',string $sSfx='') : string { return ($this->GetStrNz($sDef,$sPfx,$sSfx)); }
    public function RefIt(string &$s) : void { $this->RefStr($s); }

    // ++ ACCESS: internal ++ //

    protected function TypeOk(mixed $v) : bool { return is_string($v); }

    // -- ACCESS -- //
}