1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 20:27:31 +02:00

Fix SoapFault when detail is nested object, fixes #1431, refs #1462

This commit is contained in:
Jordi Boggiano
2020-05-21 16:39:23 +02:00
parent 74f92ea154
commit acd3173c4a
2 changed files with 27 additions and 3 deletions

View File

@@ -142,8 +142,12 @@ class NormalizerFormatter implements FormatterInterface
$data['faultactor'] = $e->faultactor;
}
if (isset($e->detail) && (is_string($e->detail) || is_object($e->detail) || is_array($e->detail))) {
$data['detail'] = is_string($e->detail) ? $e->detail : reset($e->detail);
if (isset($e->detail)) {
if (is_string($e->detail)) {
$data['detail'] = $e->detail;
} elseif (is_object($e->detail) || is_array($e->detail)) {
$data['detail'] = $this->toJson($e->detail, true);
}
}
}

View File

@@ -92,7 +92,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
}
$formatter = new NormalizerFormatter('Y-m-d');
$e = new \SoapFault('foo', 'bar', 'hello', (object) array('foo' => 'world'));
$e = new \SoapFault('foo', 'bar', 'hello', 'world');
$formatted = $formatter->format(array(
'exception' => $e,
));
@@ -110,6 +110,26 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
'detail' => 'world',
),
), $formatted);
$formatter = new NormalizerFormatter('Y-m-d');
$e = new \SoapFault('foo', 'bar', 'hello', (object) ['bar' => (object) ['biz' => 'baz'], 'foo' => 'world']);
$formatted = $formatter->format([
'exception' => $e,
]);
unset($formatted['exception']['trace']);
$this->assertEquals([
'exception' => [
'class' => 'SoapFault',
'message' => 'bar',
'code' => 0,
'file' => $e->getFile().':'.$e->getLine(),
'faultcode' => 'foo',
'faultactor' => 'hello',
'detail' => '{"bar":{"biz":"baz"},"foo":"world"}',
],
], $formatted);
}
public function testFormatToStringExceptionHandle()