/** * @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(); return $formatter->format($message->getBody()); } $factory = new StringFactoryFormatter(); return $factory->format($message->getBody()); }
/** * @param string $string * @return FormatterInterface */ public static function factoryClassName($string) { if (JsonStringFormatter::isJsonString($string)) { return JsonStringFormatter::class; } elseif (XmlStringFormatter::isXmlString($string)) { return XmlStringFormatter::class; } else { return StringFormatter::class; } }