|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright 2016 Johannes M. Schmitt <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace JMS\Serializer\Metadata; |
|
22
|
|
|
|
|
23
|
|
|
use JMS\Serializer\Exception\ExpressionLanguageRequiredException; |
|
24
|
|
|
use JMS\Serializer\Exception\LogicException; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @Annotation |
|
28
|
|
|
* @Target("METHOD") |
|
29
|
|
|
* |
|
30
|
|
|
* @author Asmir Mustafic <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
class ExpressionPropertyMetadata extends PropertyMetadata |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
public $expression; |
|
38
|
|
|
|
|
39
|
10 |
|
public function __construct($class, $fieldName, $expression) |
|
40
|
|
|
{ |
|
41
|
10 |
|
$this->class = $class; |
|
42
|
10 |
|
$this->name = $fieldName; |
|
43
|
10 |
|
$this->expression = $expression; |
|
44
|
10 |
|
$this->readOnly = true; |
|
45
|
10 |
|
} |
|
46
|
|
|
|
|
47
|
9 |
|
public function setAccessor($type, $getter = null, $setter = null) |
|
48
|
|
|
{ |
|
49
|
9 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setValue($obj, $value) |
|
52
|
|
|
{ |
|
53
|
|
|
throw new LogicException('ExpressionPropertyMetadata is immutable.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function serialize() |
|
57
|
|
|
{ |
|
58
|
|
|
return serialize([ |
|
59
|
|
|
$this->sinceVersion, |
|
60
|
|
|
$this->untilVersion, |
|
61
|
|
|
$this->groups, |
|
62
|
|
|
$this->serializedName, |
|
63
|
|
|
$this->type, |
|
64
|
|
|
$this->xmlCollection, |
|
65
|
|
|
$this->xmlCollectionInline, |
|
66
|
|
|
$this->xmlEntryName, |
|
67
|
|
|
$this->xmlKeyAttribute, |
|
68
|
|
|
$this->xmlAttribute, |
|
69
|
|
|
$this->xmlValue, |
|
70
|
|
|
$this->xmlNamespace, |
|
71
|
|
|
$this->xmlKeyValuePairs, |
|
72
|
|
|
$this->xmlElementCData, |
|
73
|
|
|
$this->xmlAttributeMap, |
|
74
|
|
|
$this->maxDepth, |
|
75
|
|
|
$this->getter, |
|
76
|
|
|
$this->setter, |
|
77
|
|
|
$this->inline, |
|
78
|
|
|
$this->readOnly, |
|
79
|
|
|
$this->class, |
|
80
|
|
|
$this->name, |
|
81
|
|
|
'excludeIf' => $this->excludeIf, |
|
82
|
|
|
'expression' => $this->expression, |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function unserialize($str) |
|
87
|
|
|
{ |
|
88
|
|
|
$unserialized = unserialize($str); |
|
89
|
|
|
list( |
|
90
|
|
|
$this->sinceVersion, |
|
91
|
|
|
$this->untilVersion, |
|
92
|
|
|
$this->groups, |
|
93
|
|
|
$this->serializedName, |
|
94
|
|
|
$this->type, |
|
95
|
|
|
$this->xmlCollection, |
|
96
|
|
|
$this->xmlCollectionInline, |
|
97
|
|
|
$this->xmlEntryName, |
|
98
|
|
|
$this->xmlKeyAttribute, |
|
99
|
|
|
$this->xmlAttribute, |
|
100
|
|
|
$this->xmlValue, |
|
101
|
|
|
$this->xmlNamespace, |
|
102
|
|
|
$this->xmlKeyValuePairs, |
|
103
|
|
|
$this->xmlElementCData, |
|
104
|
|
|
$this->xmlAttributeMap, |
|
105
|
|
|
$this->maxDepth, |
|
106
|
|
|
$this->getter, |
|
107
|
|
|
$this->setter, |
|
108
|
|
|
$this->inline, |
|
109
|
|
|
$this->readOnly, |
|
110
|
|
|
$this->class, |
|
111
|
|
|
$this->name |
|
112
|
|
|
) = $unserialized; |
|
113
|
|
|
|
|
114
|
|
|
if (isset($unserialized['excludeIf'])) { |
|
115
|
|
|
$this->excludeIf = $unserialized['excludeIf']; |
|
116
|
|
|
} |
|
117
|
|
|
if (isset($unserialized['expression'])) { |
|
118
|
|
|
$this->expression = $unserialized['expression']; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|