Exemplo n.º 1
0
 /**
  * Returns the environment variable SCRIPT_FILENAME which represents the
  * absolute pathname of the currently executing script.
  *
  * @see http://stackoverflow.com/questions/5001326/php-strange-document-root
  * @return mixed
  */
 public static function getScriptFileName()
 {
     return CacheUtil::getFromCache(self::getCache(), __FUNCTION__, function () {
         if (self::isCliRequest()) {
             return self::getScriptName();
         }
         $scriptName = FileUtil::normalizePath(dirname(self::getScriptName()));
         while (!StringUtil::endsWith(ABLERON_ROOT_DIR, $scriptName) && $scriptName !== '/') {
             $scriptName = FileUtil::normalizePath(dirname($scriptName));
         }
         return ($scriptName === '/' ? ABLERON_ROOT_DIR : StringUtil::getSubstring(ABLERON_ROOT_DIR, 0, StringUtil::getLastIndexOf(ABLERON_ROOT_DIR, $scriptName))) . self::getScriptName();
     });
 }
Exemplo n.º 2
0
 /**
  * Resolves this relative URI using the given absolute base URI.
  *
  * Does not change this Uri object in case this URI is already absolute.
  *
  * @param \Ableron\Lib\Net\Uri $baseUri The absolute base URI used to resolve this relative URI
  * @throws \Ableron\Core\Exception\SystemException
  * @return \Ableron\Lib\Net\Uri
  */
 public function resolve(Uri $baseUri)
 {
     // check whether base URI is absolute
     if (!$baseUri->isAbsolute()) {
         throw new SystemException(sprintf('Unable to resolve URI using base URI "%s" - Base URI must be absolute!', $baseUri->toString()), 0, E_USER_NOTICE, __FILE__, __LINE__);
     }
     // check whether URI is already absolute
     if ($this->isAbsolute()) {
         $this->setPath(self::removeDotSegments($this->path));
         return $this;
     }
     // resolve scheme specific part
     if ($this->host !== null) {
         $this->setPath(self::removeDotSegments($this->path));
     } else {
         // resolve authority part
         $this->setUserInfo($baseUri->getRawUserInfo());
         $this->setHost($baseUri->getRawHost());
         $this->setPort($baseUri->getPort());
         // resolve path and query
         if ($this->path === '') {
             $this->setPath($baseUri->getRawPath());
             if ($this->query === null) {
                 $this->setQuery($baseUri->getRawQuery());
             }
         } else {
             if (StringUtil::startsWith($this->path, '/')) {
                 $this->setPath(self::removeDotSegments($this->path));
             } else {
                 $this->setPath(self::removeDotSegments($baseUri->getRawHost() !== null && $baseUri->getRawPath() === '' ? '/' : StringUtil::getSubstring($baseUri->getRawPath(), 0, StringUtil::getLastIndexOf($baseUri->getRawPath(), '/') + 1) . $this->path));
             }
         }
     }
     // resolve scheme
     $this->setScheme($baseUri->getScheme());
     // return reference of this object
     return $this;
 }