function parse($trust_root, $check_sanity = false) { if (!is_string($trust_root)) { return null; } // porting note: PHP's parse_url() is not intended for url validation. $url_parts = parse_url($trust_root); if (!$url_parts || !count($url_parts)) { return false; } $proto = isset($url_parts['scheme']) ? $url_parts['scheme'] : null; $host = isset($url_parts['host']) ? $url_parts['host'] : null; $port = isset($url_parts['port']) ? $url_parts['port'] : null; $path = isset($url_parts['path']) ? $url_parts['path'] : null; // check for valid prototype $protocols = explode('|', _oid_protocol_list); if (!in_array($proto, $protocols)) { return null; } // extract wildcard if it is there if (strchr($host, '*')) { // wildcard must be at start of domain) { *.foo.com, not foo.*.com if (!TrustRoot::startsWith($host, '*')) { return null; } // there should also be a '.' ala *.schtuff.com if ($host[1] != '.') { return null; } $host = substr($host, 2); $wilcard = true; } else { $wilcard = false; } // at least needs to end in a top-level-domain $ends_in_tld = false; $_top_level_domains = explode('|', _oid_top_level_domains_list); foreach ($_top_level_domains as $tld) { if (TrustRoot::endsWith($host, $tld)) { $ends_in_tld = true; break; } } if (!$ends_in_tld) { return null; } // we have a valid trust root $tr = new TrustRoot($trust_root, $proto, $wilcard, $host, $port, $path); if ($check_sanity) { if (!$tr->isSane()) { return null; } } return $tr; }