-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCustomGetSetNormalizer.php
More file actions
46 lines (40 loc) · 1.14 KB
/
CustomGetSetNormalizer.php
File metadata and controls
46 lines (40 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* Created by PhpStorm.
* User: evaisse
* Date: 05/05/15
* Time: 15:38
*/
namespace evaisse\SimpleHttpBundle\Serializer;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
class CustomGetSetNormalizer extends GetSetMethodNormalizer
{
/**
* {@inheritdoc}
*/
public function normalize(mixed $object, ?string $format = null, array $context = [])
{
if ($object instanceof \Throwable) {
return $this->normalizeThrowable($object);
}
return parent::normalize($object, $format, $context);
}
/**
* @param \Throwable $e throwable to normalize
* @return array normalized output
*/
protected function normalizeThrowable(\Throwable $e)
{
$data = array(
'class' => get_class($e),
'message' => $e->getMessage(),
'code' => $e->getCode(),
'file' => $e->getFile().':'.$e->getLine(),
'trace' => $e->getTraceAsString(),
);
if ($previous = $e->getPrevious()) {
$data['previous'] = $this->normalizeThrowable($previous);
}
return $data;
}
}