1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\Serializer\Context; |
4
|
|
|
|
5
|
|
|
use Bdf\Serializer\Metadata\PropertyMetadata; |
6
|
|
|
use Bdf\Serializer\Normalizer\NormalizerInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* DenormalizationContext |
10
|
|
|
*/ |
11
|
|
|
class DenormalizationContext extends Context |
12
|
|
|
{ |
13
|
|
|
//List of denormalization options |
14
|
|
|
const DATETIME_FORMAT = 'dateFormat'; |
15
|
|
|
const TIMEZONE = 'dateTimezone'; |
16
|
|
|
const TIMEZONE_HINT = 'timezoneHint'; |
17
|
|
|
const THROWS_ON_ACCESSOR_ERROR = 'throws_on_accessor_error'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The default options of this context |
21
|
|
|
* |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $defaultOptions = [ |
25
|
|
|
/** |
26
|
|
|
* Throws exception if accessor has error |
27
|
|
|
* |
28
|
|
|
* @var boolean |
29
|
|
|
*/ |
30
|
|
|
self::THROWS_ON_ACCESSOR_ERROR => false, |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
96 |
|
public function __construct(NormalizerInterface $normalizer, array $options = []) |
37
|
|
|
{ |
38
|
96 |
|
parent::__construct($normalizer, $options + $this->defaultOptions); |
39
|
96 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
4 |
|
protected function prepareOptions(array $options): void |
45
|
|
|
{ |
46
|
4 |
|
$this->options = array_merge($this->options, $options); |
47
|
4 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Should the property be skipped |
51
|
|
|
* |
52
|
|
|
* @param PropertyMetadata $property |
53
|
|
|
* |
54
|
|
|
* @return boolean Returns true if skipped |
55
|
|
|
*/ |
56
|
60 |
|
public function skipProperty(PropertyMetadata $property): bool |
57
|
|
|
{ |
58
|
60 |
|
return $property->readOnly; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Should add metadata of type into the serialization |
63
|
|
|
* |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
6 |
|
public function throwsOnAccessorError(): bool |
67
|
|
|
{ |
68
|
6 |
|
return $this->options[self::THROWS_ON_ACCESSOR_ERROR]; |
69
|
|
|
} |
70
|
|
|
} |