get() public method

Returns the named header(s).
public get ( string $name, mixed $default = null, boolean $first = true ) : string | array
$name string the name of the header to return
$default mixed the value to return in case the named header does not exist
$first boolean whether to only return the first header of the specified name. If false, all headers of the specified name will be returned.
return string | array the named header(s). If `$first` is true, a string will be returned; If `$first` is false, an array will be returned.
コード例 #1
0
 /**
  * @return bool
  */
 private function checkHeaders()
 {
     if (!isset($this->currentParams['headers'])) {
         return true;
     }
     $originalStructure = $this->currentParams['headers'];
     /**
      * if token validator is active
      */
     foreach ($originalStructure as $header) {
         if (!$this->requestHeaders->get($header)) {
             throw new InvalidParamException(\Yii::t('system', 'Header \'{0}\' is empty', [$header]), 406);
         }
     }
     return true;
 }
コード例 #2
0
ファイル: Response.php プロジェクト: yiisoft/yii2-httpclient
 /**
  * Detects format from headers.
  * @param HeaderCollection $headers source headers.
  * @return null|string format name, 'null' - if detection failed.
  */
 protected function detectFormatByHeaders(HeaderCollection $headers)
 {
     $contentType = $headers->get('content-type');
     if (!empty($contentType)) {
         if (stripos($contentType, 'json') !== false) {
             return Client::FORMAT_JSON;
         }
         if (stripos($contentType, 'urlencoded') !== false) {
             return Client::FORMAT_URLENCODED;
         }
         if (stripos($contentType, 'xml') !== false) {
             return Client::FORMAT_XML;
         }
     }
     return null;
 }