本文整理汇总了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();
}
}
示例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);
}
示例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;
}
示例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);
}
}
}
}
}
示例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'));
}
示例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);
}
示例7: isContentType
/**
* {@inheritdoc}
*/
public function isContentType($type)
{
return $this->response->isContentType($type);
}