/**
  * Parses the request url and get the api path
  *
  * @return string api path
  */
 protected function getPath()
 {
     $fullPath = $_SERVER['REQUEST_URI'];
     $path = urldecode(Util::removeCommonPath($fullPath, $_SERVER['SCRIPT_NAME']));
     $baseUrl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
     if ($_SERVER['SERVER_PORT'] != '80') {
         $baseUrl .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'];
     } else {
         $baseUrl .= $_SERVER['SERVER_NAME'];
     }
     $this->baseUrl = $baseUrl . rtrim(substr($fullPath, 0, strlen($fullPath) - strlen($path)), '/');
     $path = preg_replace('/(\\/*\\?.*$)|(\\/$)/', '', $path);
     $path = str_replace($this->formatMap['extensions'], '', $path);
     if (Defaults::$useUrlBasedVersioning && strlen($path) && $path[0] == 'v') {
         $version = intval(substr($path, 1));
         if ($version && $version <= $this->apiVersion) {
             $this->requestedApiVersion = $version;
             $path = explode('/', $path, 2);
             $path = $path[1];
         }
     } elseif ($this->apiVersion) {
         $this->requestedApiVersion = $this->apiVersion;
     }
     return $path;
 }
示例#2
0
 /**
  * Parses the request url and get the api path
  *
  * @return string api path
  */
 protected function getPath()
 {
     // fix SCRIPT_NAME for PHP 5.4 built-in web server
     if (false === strpos($_SERVER['SCRIPT_NAME'], '.php')) {
         $_SERVER['SCRIPT_NAME'] = '/' . Util::removeCommonPath($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT']);
     }
     $fullPath = urldecode($_SERVER['REQUEST_URI']);
     $path = Util::removeCommonPath($fullPath, $_SERVER['SCRIPT_NAME']);
     $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : '80';
     $https = $port == '443' || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on';
     $baseUrl = ($https ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'];
     if (!$https && $port != '80' || $https && $port != '443') {
         $baseUrl .= ':' . $port;
     }
     $this->baseUrl = rtrim($baseUrl . substr($fullPath, 0, strlen($fullPath) - strlen($path)), '/');
     $path = rtrim(strtok($path, '?'), '/');
     //remove query string and trailing slash if found any
     $path = str_replace(array_merge($this->formatMap['extensions'], $this->formatOverridesMap['extensions']), '', $path);
     if (Defaults::$useUrlBasedVersioning && strlen($path) && $path[0] == 'v') {
         $version = intval(substr($path, 1));
         if ($version && $version <= $this->apiVersion) {
             $this->requestedApiVersion = $version;
             $path = explode('/', $path, 2);
             $path = $path[1];
         }
     } else {
         $this->requestedApiVersion = $this->apiMinimumVersion;
     }
     return $path;
 }