コード例 #1
0
ファイル: Restler.php プロジェクト: Samara94/dolibarr
 protected function negotiateCharset()
 {
     if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
         $found = false;
         $charList = Util::sortByPriority($_SERVER['HTTP_ACCEPT_CHARSET']);
         foreach ($charList as $charset => $quality) {
             if (in_array($charset, Defaults::$supportedCharsets)) {
                 $found = true;
                 Defaults::$charset = $charset;
                 break;
             }
         }
         if (!$found) {
             if (strpos($_SERVER['HTTP_ACCEPT_CHARSET'], '*') !== false) {
                 //use default charset
             } else {
                 throw new RestException(406, 'Content negotiation failed. ' . 'Requested charset is not supported');
             }
         }
     }
 }
コード例 #2
0
 /**
  * An initialize function to allow use of the restler error generation
  * functions for pre-processing and pre-routing of requests.
  */
 public function init()
 {
     if (Defaults::$crossOriginResourceSharing && $this->requestMethod == 'OPTIONS') {
         if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
             header('Access-Control-Allow-Methods: ' . Defaults::$accessControlAllowMethods);
         }
         if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
             header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
         }
         exit(0);
     }
     if (empty($this->formatMap)) {
         $this->setSupportedFormats('JsonFormat');
     }
     $this->url = $this->getPath();
     $this->requestMethod = Util::getRequestMethod();
     $this->responseFormat = $this->getResponseFormat();
     $this->requestFormat = $this->getRequestFormat();
     $this->responseFormat->restler = $this;
     if (is_null($this->requestFormat)) {
         $this->requestFormat = $this->responseFormat;
     } else {
         $this->requestFormat->restler = $this;
     }
     if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
         $found = false;
         $charList = Util::sortByPriority($_SERVER['HTTP_ACCEPT_CHARSET']);
         foreach ($charList as $charset => $quality) {
             if (in_array($charset, Defaults::$supportedCharsets)) {
                 $found = true;
                 Defaults::$charset = $charset;
                 break;
             }
         }
         if (!$found) {
             if (strpos($_SERVER['HTTP_ACCEPT_CHARSET'], '*') !== false) {
                 //use default charset
             } else {
                 $this->handleError(406, 'Content negotiation failed. ' . "Requested charset is not supported");
             }
         }
     }
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $found = false;
         $langList = Util::sortByPriority($_SERVER['HTTP_ACCEPT_LANGUAGE']);
         foreach ($langList as $lang => $quality) {
             foreach (Defaults::$supportedLanguages as $supported) {
                 if (strcasecmp($supported, $lang) == 0) {
                     $found = true;
                     Defaults::$language = $supported;
                     break;
                 }
             }
         }
         if (!$found) {
             if (strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], '*') !== false) {
                 //use default language
             } else {
                 //ignore
             }
         }
     }
 }
コード例 #3
0
ファイル: Restler.php プロジェクト: poqcz/restler
 protected function negotiateCharset()
 {
     $accept_charset = null;
     if (is_null($this->requestFromObject)) {
         if (array_key_exists('HTTP_ACCEPT_CHARSET', $_SERVER)) {
             $accept_charset = $_SERVER['HTTP_ACCEPT_CHARSET'];
         }
     } else {
         $accept_charset = $this->requestFromObject->getHeader()->get('Accept-Charset');
         if (!is_null($accept_charset)) {
             $accept_charset = $accept_charset->getValue();
         }
     }
     if (!is_null($accept_charset)) {
         $found = false;
         $charList = Util::sortByPriority($accept_charset);
         foreach ($charList as $charset => $quality) {
             if (in_array($charset, Defaults::$supportedCharsets)) {
                 $found = true;
                 Defaults::$charset = $charset;
                 break;
             }
         }
         if (!$found) {
             if (strpos($accept_charset, '*') !== false) {
                 //use default charset
             } else {
                 throw new RestException(406, 'Content negotiation failed. ' . 'Requested charset is not supported');
             }
         }
     }
 }