public static function test() { // A few examples. echo "Testing CPENamingBind...<br>\n"; $wfn = new WellFormedName("a", "microsoft", "internet_explorer", "8\\.0\\.6001", "beta", new LogicalValue("ANY"), "sp2", null, null, null, null); $wfn2 = new WellFormedName(); $wfn2->set("part", "a"); $wfn2->set("vendor", "foo\\\$bar"); $wfn2->set("product", "insight"); $wfn2->set("version", "7\\.4\\.0\\.1570"); $wfn2->set("target_sw", "win2003"); $wfn2->set("update", new LogicalValue("NA")); $wfn2->set("sw_edition", "online"); $wfn2->set("target_hw", "x64"); $cpenb = new CPENameBinder(); echo $cpenb->bindToURI($wfn) . "<br>\n"; echo $cpenb->bindToFS($wfn2) . "<br>\n"; }
/** * Unpacks the elements in s and sets the attributes in the given * WellFormedName accordingly. * @param $s packed string * @param $wfn WellFormedName * @return The augmented WellFormedName. */ private function unpack($s, WellFormedName $wfn) { // Parse out the five elements. $start = 1; $ed = ""; $sw_edition = ""; $t_sw = ""; $t_hw = ""; $oth = ""; $end = strpos($s, "~", $start); if ($start == $end) { $ed = ""; } else { $ed = substr($s, $start, $end - $start); } $start = $end + 1; $end = strpos($s, "~", $start); if ($start == $end) { $sw_edition = ""; } else { $sw_edition = substr($s, $start, $end - $start); } $start = $end + 1; $end = strpos($s, "~", $start); if ($start == $end) { $t_sw = ""; } else { $t_sw = substr($s, $start, $end - $start); } $start = $end + 1; $end = strpos($s, "~", $start); if ($start == $end) { $t_hw = ""; } else { $t_hw = substr($s, $start, $end - $start); } $start = $end + 1; if ($start >= strlen($s)) { $oth = ""; } else { $oth = substr($s, $start, strlen($s) - 1 - $start); } // Set each component in the WFN. try { $wfn->set("edition", $this->decode($ed)); $wfn->set("sw_edition", $this->decode($sw_edition)); $wfn->set("target_sw", $this->decode($t_sw)); $wfn->set("target_hw", $this->decode($t_hw)); $wfn->set("other", $this->decode($oth)); } catch (Exception $e) { echo $e->getMessage() . "\n"; } return $wfn; }