Ferreteria/v0.6/clade/Sys/FileSys/Aspect/Ident/spex/USpec/@code/cur/2026/06/02

From WoozleCodes
Jump to navigation Jump to search
2026/06/01 2026/06/02 2026/06/03

Works ok as far as it goes.

interface iURL {
    // ACCESS: direct
    public ?string  $SProto { get; }
    public string   $SHost  { get; }
    public int      $NPort  { get; }
    public string   $SUser  { get; }
    public string   $SPass  { get; }
    public string   $SPath  { get; set; }
    public ?string  $SQuery { get; }
    public string   $SFrag  { get; }
    // ACCESS: calculated
    public string $SProtoMk { get; }
    public string $SPortMk  { get; }
    public string $SPassMk  { get; }
    public string $SUserMk  { get; }
    public string $SPrefix  { get; }
    public string $SFull    { get; set; }
}
class cnURL implements iURL {

    static public function FromSpec(string $fs) : SelfIface {
        $oThis = new static;
        $oThis->SFull = $fs;
        return $oThis;
    }
    #public function __construct(array $ar) { $this->ar = $ar; }

    // ++ ACCESS: direct ++ //

    private $ar;
    protected function GetItNz(string $sName, $def=NULL, ?string $sPfx=NULL, ?string $sSfx=NULL) {
        if (array_key_exists($sName,$this->ar)) {
            return $sPfx . $this->ar[$sName] . $sSfx;
        } else {
            return $def;
        }
    }
    // 2022-10-25 Just using this where immediately needed; will probably need to use in more of the below methods.

    public ?string  $SProto { get { return array_key_exists('scheme',$this->ar) ? $this->ar['scheme'] : NULL; } } // protocol:
    public string   $SHost  { get { return $this->GetItNz('host',''); } }   // domain/address
    public int      $NPort  { get { return $this->ar['port']; } }   // port number (if specified)
    public string   $SUser  { get { return $this->ar['user']; } }
    public string   $SPass  { get { return $this->ar['pass']; } }
    public string   $SPath  { get { return $this->ar['path']; } set(string $s) { $this->ar['path'] = $s; } }
    public ?string  $SQuery { get { return $this->GetItNz('query'); } }  // after the question mark ?
    public string   $SFrag  { get { return $this->ar['fragment']; } }    // after the "#"

    // ++ ACCESS: calculated ++ //

    // *Mk() functions include the necessary URL markup *if* the part is set

    public string $SProtoMk { get { return $this->GetItNz('scheme','','','://'); } }
    public string $SPortMk  { get { return $this->GetItNz('port','',':'); } }
    public string $SPassMk  { get { return $this->GetItNz('pass','',':'); } }
    public string $SUserMk  { get { return $this->GetItNz('user','','','@'); } }

    public string $SFull {
        get { return $this->SPrefix . $this->SPath; }
        set(string $fs) { $this->ar = parse_url($fs); }
    }
    public string $SPrefix {
        get {
            return
              $this->SProtoMk
              .$this->SUserMk
              .$this->SHost
              .$this->SPortMk
              .$this->SPassMk
              ;
        }
    }

    // ++ ACCESS: diagnostics ++ //

    public function VIEW_Inline() : string {
        return
            ' PROTO=['.$this->SProtoMk.']'
            .' USER=['.$this->SUserMk.']'
            .' HOST=['.$this->SHost.']'
            .' PORT=['.$this->SPortMk.']'
            .' PASS=['.$this->SPassMk.']'
            .' PATH=['.$this->SPath.']'
            ;
    }

    // -- ACCESS -- //
}