Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • AbstractCommand
  • ClosureCommand
  • DefaultRequestSerializer
  • DefaultResponseParser
  • OperationCommand
  • OperationResponseParser

Interfaces

  • CommandInterface
  • RequestSerializerInterface
  • ResponseClassInterface
  • ResponseParserInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: namespace Guzzle\Service\Command;
 4: 
 5: use Guzzle\Http\Message\Response;
 6: 
 7: /**
 8:  * Default HTTP response parser used to marshal JSON responses into arrays and XML responses into SimpleXMLElement
 9:  */
10: class DefaultResponseParser implements ResponseParserInterface
11: {
12:     /**
13:      * @var self
14:      */
15:     protected static $instance;
16: 
17:     /**
18:      * Get a cached instance of the default response parser
19:      * @return self
20:      * @codeCoverageIgnore
21:      */
22:     public static function getInstance()
23:     {
24:         if (!self::$instance) {
25:             self::$instance = new self;
26:         }
27: 
28:         return self::$instance;
29:     }
30: 
31:     /**
32:      * {@inheritdoc}
33:      */
34:     public function parse(CommandInterface $command)
35:     {
36:         $response = $command->getRequest()->getResponse();
37: 
38:         // Account for hard coded content-type values specified in service descriptions
39:         if ($contentType = $command->get('command.expects')) {
40:             $response->setHeader('Content-Type', $contentType);
41:         } else {
42:             $contentType = (string) $response->getHeader('Content-Type');
43:         }
44: 
45:         return $this->handleParsing($command, $response, $contentType);
46:     }
47: 
48:     /**
49:      * {@inheritdoc}
50:      */
51:     protected function handleParsing(AbstractCommand $command, Response $response, $contentType)
52:     {
53:         $result = $response;
54:         if ($result->getBody()) {
55:             if (stripos($contentType, 'json') !== false) {
56:                 $result = $result->json();
57:             } if (stripos($contentType, 'xml') !== false) {
58:                 $result = $result->xml();
59:             }
60:         }
61: 
62:         return $result;
63:     }
64: }
65: 
php-coveralls API documentation generated by ApiGen 2.8.0