Open Journal Systems  3.3.0
DefaultResponseParser.php
1 <?php
2 
3 namespace Guzzle\Service\Command;
4 
6 
11 {
13  protected static $instance;
14 
19  public static function getInstance()
20  {
21  if (!self::$instance) {
22  self::$instance = new self;
23  }
24 
25  return self::$instance;
26  }
27 
28  public function parse(CommandInterface $command)
29  {
30  $response = $command->getRequest()->getResponse();
31 
32  // Account for hard coded content-type values specified in service descriptions
33  if ($contentType = $command['command.expects']) {
34  $response->setHeader('Content-Type', $contentType);
35  } else {
36  $contentType = (string) $response->getHeader('Content-Type');
37  }
38 
39  return $this->handleParsing($command, $response, $contentType);
40  }
41 
42  protected function handleParsing(CommandInterface $command, Response $response, $contentType)
43  {
44  $result = $response;
45  if ($result->getBody()) {
46  if (stripos($contentType, 'json') !== false) {
47  $result = $result->json();
48  } elseif (stripos($contentType, 'xml') !== false) {
49  $result = $result->xml();
50  }
51  }
52 
53  return $result;
54  }
55 }
Guzzle\Service\Command
Definition: AbstractCommand.php:3
Guzzle\Service\Command\ResponseParserInterface
Definition: ResponseParserInterface.php:8
Guzzle\Service\Command\DefaultResponseParser\handleParsing
handleParsing(CommandInterface $command, Response $response, $contentType)
Definition: DefaultResponseParser.php:42
Guzzle\Http\Message\Response
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:17
Guzzle\Service\Command\DefaultResponseParser
Definition: DefaultResponseParser.php:10
Guzzle\Service\Command\DefaultResponseParser\parse
parse(CommandInterface $command)
Definition: DefaultResponseParser.php:28
Guzzle\Service\Command\CommandInterface
Definition: CommandInterface.php:17
Guzzle\Service\Command\DefaultResponseParser\$instance
static $instance
Definition: DefaultResponseParser.php:13
Guzzle\Service\Command\CommandInterface\getRequest
getRequest()
Guzzle\Service\Command\DefaultResponseParser\getInstance
static getInstance()
Definition: DefaultResponseParser.php:19