コード例 #1
0
 /**
  * @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());
 }
コード例 #2
0
 /**
  * @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;
     }
 }