當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Request::headers方法代碼示例

本文整理匯總了PHP中Slim\Http\Request::headers方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::headers方法的具體用法?PHP Request::headers怎麽用?PHP Request::headers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Slim\Http\Request的用法示例。


在下文中一共展示了Request::headers方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 protected function __construct(\Slim\Http\Request $request)
 {
     $key = $request->headers('apikey');
     if ($key == '') {
         $key = $request->post('apikey');
     }
     if ($key == '') {
         $key = $request->get('apikey');
     }
     if ($key == '') {
         return;
     }
     $this->apiKey = $key;
     $this->role = $this->getRoleFromKey($this->apiKey);
 }
開發者ID:QualityUnit,項目名稱:swagger-codegen,代碼行數:15,代碼來源:Auth.class.php

示例2: etag

 /**
  * Set ETag HTTP Response Header
  *
  * Set the etag header and stop if the conditional GET request matches.
  * The `value` argument is a unique identifier for the current resource.
  * The `type` argument indicates whether the etag should be used as a strong or
  * weak cache validator.
  *
  * When the current request includes an 'If-None-Match' header with
  * a matching etag, execution is immediately stopped. If the request
  * method is GET or HEAD, a '304 Not Modified' response is sent.
  *
  * @param  string                    $value The etag value
  * @param  string                    $type  The type of etag to create; either "strong" or "weak"
  * @throws \InvalidArgumentException If provided type is invalid
  */
 public function etag($value, $type = 'strong')
 {
     //Ensure type is correct
     if (!in_array($type, array('strong', 'weak'))) {
         throw new \InvalidArgumentException('Invalid Slim::etag type. Expected "strong" or "weak".');
     }
     //Set etag value
     $value = '"' . $value . '"';
     if ($type === 'weak') {
         $value = 'W/' . $value;
     }
     $this->response['ETag'] = $value;
     //Check conditional GET
     if ($etagsHeader = $this->request->headers('IF_NONE_MATCH')) {
         $etags = preg_split('@\\s*,\\s*@', $etagsHeader);
         if (in_array($value, $etags) || in_array('*', $etags)) {
             $this->halt(304);
         }
     }
 }
開發者ID:sydorenkovd,項目名稱:Rest-slim-news,代碼行數:36,代碼來源:Slim.php

示例3: extractToken

 public function extractToken(Request $request)
 {
     $headers = $request->headers();
     $rawHeaders = $request->rawHeaders();
     if (isset($rawHeaders['Authorization'])) {
         $header = $rawHeaders['Authorization'];
     } elseif (isset($headers['Authorization'])) {
         $header = $headers['Authorization'];
     } else {
         throw new Exception('Authorization header required.');
     }
     if (preg_match('/Basic\\s+(.*)$/i', $header, $matches)) {
         list($authUser, $authPass) = explode(':', base64_decode($matches[1]));
     } else {
         throw new Exception('Authorization header invalid.');
     }
     if (isset($authUser) && isset($authPass)) {
         try {
             $token = $this->fetchToken($authUser, $authPass);
         } catch (\Exception $e) {
             throw new Exception('Authorization header invalid.');
         }
     }
     return $token;
 }
開發者ID:rohanabraham,項目名稱:lxHive,代碼行數:25,代碼來源:Basic.php

示例4: extractToken

 public function extractToken(Request $request)
 {
     $tokenHeader = $request->headers('Authorization', false);
     $rawTokenHeader = $request->rawHeaders('Authorization', false);
     if ($tokenHeader && preg_match('/Bearer\\s*([^\\s]+)/', $tokenHeader, $matches)) {
         $tokenHeader = $matches[1];
     } elseif ($rawTokenHeader && preg_match('/Bearer\\s*([^\\s]+)/', $rawTokenHeader, $matches)) {
         $tokenHeader = $matches[1];
     } else {
         $tokenHeader = false;
     }
     $tokenRequest = $request->post('access_token', false);
     $tokenQuery = $request->get('access_token', false);
     // At least one (and only one) of client credentials method required.
     if (!$tokenHeader && !$tokenRequest && !$tokenQuery) {
         throw new Exception('The request is missing a required parameter.', Resource::STATUS_BAD_REQUEST);
     } elseif ($tokenHeader && $tokenRequest || $tokenRequest && $tokenQuery || $tokenQuery && $tokenHeader) {
         throw new Exception('The request includes multiple credentials.', Resource::STATUS_BAD_REQUEST);
     }
     $accessToken = $tokenHeader ?: $tokenRequest ?: $tokenQuery;
     try {
         $tokenDocument = $this->fetchToken($accessToken);
     } catch (\Exception $e) {
         throw new Exception('Access token invalid.');
     }
     return $tokenDocument;
 }
開發者ID:rohanabraham,項目名稱:lxHive,代碼行數:27,代碼來源:OAuth.php


注:本文中的Slim\Http\Request::headers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。