uriStr = phutil_string_cast($uri); // A PhutilURI may be useful. If available, import that as-is. // Note that the constructor PhutilURI(string) is a bit expensive. if ($uri instanceof PhutilURI) { $this->phutilUri = $uri; } } /** * Check if the URI points to Phorge itself. * @return bool */ public function isSelf() { // The backend prefers a PhutilURI object, if available. $uri = $this->phutilUri ? $this->phutilUri : $this->uriStr; return PhabricatorEnv::isSelfURI($uri); } /** * Check whenever an URI is just a simple fragment without path and protocol. * @return bool */ public function isAnchor() { return $this->isStartingWithChar('#'); } /** * Check whenever an URI starts with a slash (no protocol, etc.) * @return bool */ public function isStartingWithSlash() { return $this->isStartingWithChar('/'); } /** * A sane default. */ public function __toString() { return $this->uriStr; } /** * Check whenever the URI starts with the provided character. * @param string $char String that MUST have length of 1. * @return bool */ private function isStartingWithChar($char) { return strncmp($this->uriStr, $char, 1) === 0; } }