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


PHP Response::isContentType方法代码示例

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


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

示例1: getContent

 private function getContent(Response $response)
 {
     if ($response->isContentType('xml')) {
         return $response->xml();
     } elseif ($response->isContentType('audio')) {
         return $response->getBody()->getStream();
     } else {
         return $response->getBody();
     }
 }
开发者ID:gquemener,项目名称:7digital-client,代码行数:10,代码来源:Service.php

示例2: computeResponse

 /**
  * @param Response $response
  * @param string $clazz
  * @return mixed
  * @throws ClassCastException
  */
 protected function computeResponse($response, $clazz)
 {
     if (false === ($response->isContentType(Constants::CONTENT_TYPE_JSON) || $response->isContentType(Constants::CONTENT_TYPE_JSON_NXENTITY))) {
         if (Blob::className !== $clazz) {
             throw new ClassCastException(sprintf('Cannot cast %s as %s', Blob::className, $clazz));
         }
         return Blob::fromHttpResponse($response);
     }
     $body = $response->getBody(true);
     return $this->nuxeoClient->getConverter()->read($body, $clazz);
 }
开发者ID:nuxeo,项目名称:nuxeo-automation-php-client,代码行数:17,代码来源:NuxeoEntity.php

示例3: getBody

 public static function getBody(GuzzleResponse $response)
 {
     $body = $response->getBody(true);
     // Response body is in JSON
     if ($response->isContentType('json')) {
         $tmp = json_decode($body, true);
         if (JSON_ERROR_NONE === json_last_error()) {
             $body = $tmp;
         }
     }
     return $body;
 }
开发者ID:apetrova0912,项目名称:buffer-php,代码行数:12,代码来源:ResponseHandler.php

示例4: printLastResponseOnError

 /**
  * @AfterScenario
  */
 public function printLastResponseOnError(BaseScenarioEvent $scenarioEvent)
 {
     if ($scenarioEvent->getResult() == StepEvent::FAILED) {
         if ($this->response) {
             $body = $this->getResponse()->getBody(true);
             // could we even ask them if they want to print out the error?
             // or do it based on verbosity
             // print some debug details
             $this->printDebug('');
             $this->printDebug('<error>Failure!</error> when making the following request:');
             $this->printDebug(sprintf('<comment>%s</comment>: <info>%s</info>', $this->lastRequest->getMethod(), $this->lastRequest->getUrl()) . "\n");
             if ($this->response->isContentType('application/json') || $this->response->isContentType('+json')) {
                 $data = json_decode($body);
                 if ($data === null) {
                     // invalid JSON!
                     $this->printDebug($body);
                 } else {
                     // valid JSON, print it pretty
                     $this->printDebug(json_encode($data, JSON_PRETTY_PRINT));
                 }
             } else {
                 // the response is HTML - see if we should print all of it or some of it
                 $isValidHtml = strpos($body, '</body>') !== false;
                 if ($this->useFancyExceptionReporting && $isValidHtml) {
                     $this->printDebug('<error>Failure!</error> Below is a summary of the HTML response from the server.');
                     // finds the h1 and h2 tags and prints them only
                     $crawler = new Crawler($body);
                     foreach ($crawler->filter('h1, h2')->extract(array('_text')) as $header) {
                         $this->printDebug(sprintf('        ' . $header));
                     }
                 } else {
                     $this->printDebug($body);
                 }
             }
         }
     }
 }
开发者ID:rllmwm,项目名称:forbiddencat,代码行数:40,代码来源:ApiFeatureContext.php

示例5: testComparesContentType

 /**
  * @covers Guzzle\Http\Message\Response::isContentType
  */
 public function testComparesContentType()
 {
     $response = new Response(200, array('Content-Type' => 'text/html; charset=ISO-8859-4'));
     $this->assertTrue($response->isContentType('text/html'));
     $this->assertTrue($response->isContentType('TExT/html'));
     $this->assertTrue($response->isContentType('charset=ISO-8859-4'));
     $this->assertFalse($response->isContentType('application/xml'));
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:11,代码来源:ResponseTest.php

示例6:

 function it_fails_with_invalid_http_authentication_credentials($client, $clientParameters, Request $request, Response $response, Collection $curlOptions)
 {
     $guzzleParams = ['connect_timeout' => UrlExplorer::CONNECT_TIMEOUT, 'timeout' => UrlExplorer::TIMEOUT, 'auth' => ['bad_login', 'passwd']];
     $clientParameters->getHash()->willReturn('some_hash');
     $clientParameters->getHttpLogin()->willReturn('bad_login');
     $clientParameters->getHttpPassword()->willReturn('passwd');
     $clientParameters->getSoapUrl()->willReturn('http://myvalidsoap.url/api/soap/?wsdl');
     $client->get('http://myvalidsoap.url/api/soap/?wsdl', [], $guzzleParams)->willReturn($request);
     $request->getCurlOptions()->willReturn($curlOptions);
     $curlOptions->set(CURLOPT_CONNECTTIMEOUT, UrlExplorer::CONNECT_TIMEOUT)->willReturn($request);
     $curlOptions->set(CURLOPT_TIMEOUT, UrlExplorer::TIMEOUT)->willReturn($request);
     $client->send($request)->shouldBeCalled()->willThrow('Guzzle\\Http\\Exception\\BadResponseException');
     $response->isContentType(Argument::any())->shouldNotBeCalled();
     $response->getBody(Argument::any())->shouldNotBeCalled();
     $this->shouldThrow('\\Pim\\Bundle\\MagentoConnectorBundle\\Validator\\Exception\\InvalidSoapUrlException')->duringGetUrlContent($clientParameters);
 }
开发者ID:jarocks,项目名称:MagentoConnectorBundle,代码行数:16,代码来源:UrlExplorerSpec.php

示例7: isContentType

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


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