Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
1.8 kB · 78 lines
PHP
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879<?php
/** * A simple wrapper for PhutilURI, to be aware of the * relative/absolute context, and other minor things. */final class PhutilURIHelper extends Phobject {
/** * String version of your original URI. * @var string */ private $uriStr;
/** * Structured version of your URI. * @var PhutilURI */ private $phutilUri;
/** * @param string|PhutilURI $uri */ public function __construct($uri) {
// Keep the original string for basic checks. $this->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; }
}