当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::getContentType方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Response::getContentType方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getContentType方法的具体用法?PHP Response::getContentType怎么用?PHP Response::getContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::getContentType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: request

 /**
  * Returns object with properties int:status object:body
  * @param string $method
  * @param string $path
  * @param array $query
  * @param bool $doAuth
  * @throws \InvalidArgumentException
  * @throws \Exception
  * @return \stdClass
  */
 public function request($method, $path, $query = array(), $doAuth = false)
 {
     $this->userAgent = 'Rocker REST Client v' . Server::VERSION;
     $method = strtolower($method);
     $request = $this->initiateRequest($method, $path, $query);
     if ($doAuth) {
         $this->addAuthHeader($request);
     }
     try {
         $this->lastResponse = $request->send();
     } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
         $this->lastResponse = $e->getResponse();
         if ($this->lastResponse->getStatusCode() == 401 && !$doAuth && !empty($this->user)) {
             trigger_error('Doing unauthenticated requests to an URI that requires authentication (' . $path . ')', E_WARNING);
             return $this->request($method, $path, $query, true);
         }
     }
     if ($this->lastResponse->getStatusCode() == 400) {
         throw new ClientException($this->lastResponse, 400);
     }
     if ($this->lastResponse->getStatusCode() == 204) {
         return (object) array('status' => 204, 'body' => array());
     }
     if (strpos($this->lastResponse->getContentType(), 'json') === false) {
         throw new ClientException($this->lastResponse, ClientException::ERR_UNEXPECTED_CONTENT_TYPE, 'Server responded with unexpected content type (' . $this->lastResponse->getContentType() . ')');
     }
     $str = (string) $this->lastResponse->getBody();
     $body = json_decode($str);
     return (object) array('status' => $this->lastResponse->getStatusCode(), 'headers' => $this->headerCollectionToArray($this->lastResponse->getHeaders()), 'body' => $body);
 }
开发者ID:NavalKishor,项目名称:PHP-Rocker,代码行数:40,代码来源:Client.php

示例2: __construct

 public function __construct(\Guzzle\Http\Message\Response $response, $type)
 {
     $this->_response = $response;
     // if json returned - parse and fill structure
     $contentType = $this->_response->getContentType();
     if (strpos($contentType, ';')) {
         list($contentType, ) = explode(';', $contentType);
     }
     if ($contentType == 'application/json') {
         $this->_structure = new $type($this->_response->json());
     } else {
         throw new \Exception('Structure parser for content type "' . $this->_response->getContentType() . '" not implemented');
     }
 }
开发者ID:sokil,项目名称:php-rest,代码行数:14,代码来源:Response.php

示例3: parseResponseIntoArray

 /**
  * Parses response into an array
  *
  * @param Response $response
  * @return array
  */
 protected function parseResponseIntoArray($response)
 {
     if (strpos($response->getContentType(), 'json') === false) {
         parse_str($response->getBody(true), $array);
         return $array;
     }
     return $response->json();
 }
开发者ID:opdavies,项目名称:nwdrupalwebsite,代码行数:14,代码来源:MeetupResponseParser.php

示例4: createResponse

 /**
  * Reads response meta tags to guess content-type charset.
  */
 protected function createResponse(GuzzleResponse $response)
 {
     $body = $response->getBody(true);
     $contentType = $response->getContentType();
     if (!$contentType || false === strpos($contentType, 'charset=')) {
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
     }
     $response->setHeader('Content-Type', $contentType);
     return parent::createResponse($response);
 }
开发者ID:lenninsanchez,项目名称:donadores,代码行数:15,代码来源:Client.php

示例5: createResponse

 /**
  * Reads response meta tags to guess content-type charset.
  */
 protected function createResponse(GuzzleResponse $response)
 {
     $body = $response->getBody(true);
     $statusCode = $response->getStatusCode();
     $headers = $response->getHeaders()->getAll();
     $contentType = $response->getContentType();
     if (!$contentType || false === strpos($contentType, 'charset=')) {
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
     }
     $headers['Content-Type'] = $contentType;
     return new Response($body, $statusCode, $headers);
 }
开发者ID:NaszvadiG,项目名称:ImageCMS,代码行数:17,代码来源:Client.php

示例6: factory

 /**
  * Factory method to create a new response exception based on the response code.
  *
  * @param RequestInterface $request  Request
  * @param Response         $response Response received
  * @param string           $label
  *
  * @return BadResponseException
  */
 public static function factory(RequestInterface $request, Response $response, $label = null)
 {
     if (!$label) {
         if ($response->isClientError()) {
             $label = 'Client error response';
         } elseif ($response->isServerError()) {
             $label = 'Server error response';
         } else {
             $label = 'Unsuccessful response';
         }
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl(), '[content type] ' . $response->getContentType(), '[response body] ' . $response->getBody(true)));
     $result = new static($message);
     $result->setResponse($response);
     $result->setRequest($request);
     return $result;
 }
开发者ID:aculvi,项目名称:OroCRMMailChimpBundle,代码行数:26,代码来源:BadResponseException.php

示例7: isHttpErrorFatal

 /**
  * @return bool
  */
 private function isHttpErrorFatal(Response $response, $expectedResponseContentType)
 {
     return $response->isSuccessful() && $response->getContentType() != $expectedResponseContentType;
 }
开发者ID:rezzza,项目名称:tk1-contexts,代码行数:7,代码来源:HttpResponseTimeBenchmark.php

示例8: parseResponse

 private function parseResponse(Response $response, $path)
 {
     $statusCode = $response->getStatusCode();
     if ($statusCode !== 200) {
         throw new UnexpectedValueException(sprintf('Expected status code 200 from "%s", got %d', $path, $statusCode));
     }
     $contentType = $response->hasHeader('content-type') ? $response->getContentType() : '';
     if (substr($contentType, 0, 10) !== 'text/plain') {
         throw new UnexpectedValueException(sprintf('Expected content type "text/plain" from "%s", got "%s"', $path, $contentType));
     }
     return $this->parseRequestFromResponse($response, $path);
 }
开发者ID:cosmorogers,项目名称:http-mock,代码行数:12,代码来源:RequestCollectionFacade.php

示例9: handleResponse

 /**
  * @param RequestInterface $request
  * @param Response $response
  * @return \Guzzle\Http\EntityBodyInterface|mixed|string
  */
 public function handleResponse(RequestInterface $request, Response $response)
 {
     $body = $response->getBody(true);
     switch ($response->getContentType()) {
         case "application/json":
             $body = json_decode($body, true);
             break;
     }
     return [$response->getStatusCode(), $body];
 }
开发者ID:kansch,项目名称:thelia-api-client,代码行数:15,代码来源:Client.php

示例10: getContentType

 /**
  * {@inheritdoc}
  */
 public function getContentType()
 {
     return $this->response->getContentType();
 }
开发者ID:ramunasd,项目名称:platform,代码行数:7,代码来源:GuzzleRestResponse.php

示例11: pushLinksForResponse

function pushLinksForResponse(Guzzle\Http\Message\Response $resp)
{
    $self = null;
    $hubs = [];
    $linkHeader = $resp->getHeader('link');
    if ($linkHeader instanceof Guzzle\Http\Message\Header\Link) {
        $links = $linkHeader->getLinks();
        foreach ($links as $link) {
            if (strpos(" {$link['rel']} ", ' self ') !== false) {
                $self = $link['url'];
            }
            if (strpos(" {$link['rel']} ", ' hub ') !== false) {
                $hubs[] = $link['url'];
            }
        }
    }
    if (strpos($resp->getContentType(), 'html') !== false) {
        $mf = Mf2\parse($resp->getBody(true), $resp->getEffectiveUrl());
        if (!empty($mf['rels']['hub'])) {
            $hubs = array_merge($hubs, $mf['rels']['hub']);
        }
        if (!empty($mf['rels']['self']) and $self === null) {
            $self = $mf['rels']['self'][0];
        }
    }
    return ['self' => $self, 'hub' => $hubs];
}
开发者ID:taproot,项目名称:subscriptions,代码行数:27,代码来源:subscriptions.php


注:本文中的Guzzle\Http\Message\Response::getContentType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。