Exemple #1
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'] = '/' . substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT']) + 1);
     }
     list($base, $path) = Util::splitCommonPath(urldecode($_SERVER['REQUEST_URI']), $_SERVER['SCRIPT_NAME']);
     if (!$this->baseUrl) {
         $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : '80';
         $port = isset($_SERVER['HTTP_X_FORWARDED_PORT']) ? $_SERVER['HTTP_X_FORWARDED_PORT'] : $port;
         // Amazon ELB
         $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 = $baseUrl . $base;
     } elseif (!empty($base) && false === strpos($this->baseUrl, $base)) {
         $this->baseUrl .= $base;
     }
     $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;
 }