for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Glooby\Debug\Formatter\Guzzle;
use Glooby\Debug\Formatter\FormatterInterface;
use Glooby\Debug\Formatter\JsonStringFormatter;
use Glooby\Debug\Formatter\StringFactoryFormatter;
use Glooby\Debug\Formatter\XmlStringFormatter;
use GuzzleHttp\Message\RequestInterface;
use GuzzleHttp\Message\ResponseInterface;
/**
* @author Emil Kilhage
*/
abstract class AbstractMessageFormatter implements FormatterInterface
{
* @param RequestInterface|ResponseInterface $message
* @return string
protected function formatBody($message)
$header = $message->getHeader('Content-Type');
if (JsonStringFormatter::isJsonHeader($header)) {
$formatter = new JsonStringFormatter();
return $formatter->format($message->getBody());
} elseif (XmlStringFormatter::isXmlHeader($header)) {
$formatter = new XmlStringFormatter();
}
$factory = new StringFactoryFormatter();
return $factory->format($message->getBody());
protected function formatHeaders($message)
$headers = [];
foreach ($message->getHeaders() as $header => $value) {
$headers[] = sprintf('%s: %s', $header, implode("\n : ", $value));
return implode("\n", $headers);