psl = $psl; foreach ($spec as $key => $val) { $this->$key = $val; } } /** * * Returns this Host object as a string. * * @return string The full Host this object represents. * */ public function __toString() { return $this->get(); } /** * * Returns this Host object as a string. * * @return string The full Host this object represents. * */ public function get() { if ($this->host !== null) { return $this->host; } // retain only the elements that are not empty $str = array_filter( [$this->subdomain, $this->registerable_domain], 'strlen' ); return implode('.', $str); } /** * * Sets values from a host string; overwrites any previous values. * * @param string $spec The host string to use; e.g., 'example.com'. * * @return void * */ public function setFromString($spec) { $this->host = $spec; $this->public_suffix = $this->psl->getPublicSuffix($spec); $this->registerable_domain = $this->psl->getRegisterableDomain($spec); $this->subdomain = $this->psl->getSubdomain($spec); } /** * * Returns the public suffix portion of the host. * * @return string * */ public function getPublicSuffix() { return $this->public_suffix; } /** * * Returns the subdomain portion of the host. * * @return string * */ public function getSubdomain() { return $this->subdomain; } /** * * Returns the registerable domain portion of the host. * * @return string * */ public function getRegisterableDomain() { return $this->registerable_domain; } }