コード例 #1
0
ファイル: Server.php プロジェクト: helsaba/rainloop-webmail
 /**
  * Calculates the uri for a request, making sure that the base uri is stripped out
  *
  * @param string $uri
  * @throws Exception\Forbidden A permission denied exception is thrown whenever there was an attempt to supply a uri outside of the base uri
  * @return string
  */
 public function calculateUri($uri)
 {
     if ($uri[0] != '/' && strpos($uri, '://')) {
         $uri = parse_url($uri, PHP_URL_PATH);
     }
     $uri = str_replace('//', '/', $uri);
     if (strpos($uri, $this->getBaseUri()) === 0) {
         return trim(URLUtil::decodePath(substr($uri, strlen($this->getBaseUri()))), '/');
         // A special case, if the baseUri was accessed without a trailing
         // slash, we'll accept it as well.
     } elseif ($uri . '/' === $this->getBaseUri()) {
         return '';
     } else {
         throw new Exception\Forbidden('Requested uri (' . $uri . ') is out of base uri (' . $this->getBaseUri() . ')');
     }
 }