Total Complexity | 7 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
23 | final class ReservedAttributeNameConverter implements NameConverterInterface |
||
24 | { |
||
25 | const JSON_API_RESERVED_ATTRIBUTES = [ |
||
26 | 'id' => '_id', |
||
27 | 'type' => '_type', |
||
28 | 'links' => '_links', |
||
29 | 'relationships' => '_relationships', |
||
30 | ]; |
||
31 | |||
32 | private $nameConverter; |
||
33 | |||
34 | public function __construct(NameConverterInterface $nameConverter = null) |
||
35 | { |
||
36 | $this->nameConverter = $nameConverter; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function normalize($propertyName) |
||
43 | { |
||
44 | if (null !== $this->nameConverter) { |
||
45 | $propertyName = $this->nameConverter->normalize($propertyName); |
||
46 | } |
||
47 | |||
48 | if (isset(self::JSON_API_RESERVED_ATTRIBUTES[$propertyName])) { |
||
49 | $propertyName = self::JSON_API_RESERVED_ATTRIBUTES[$propertyName]; |
||
50 | } |
||
51 | |||
52 | return $propertyName; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function denormalize($propertyName) |
||
69 | } |
||
70 | } |
||
71 |