|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace JMS\Serializer\Annotation; |
|
6
|
|
|
|
|
7
|
|
|
use JMS\Serializer\Exception\InvalidArgumentException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @Annotation |
|
11
|
|
|
* @Target({"METHOD", "CLASS"}) |
|
12
|
|
|
* |
|
13
|
|
|
* @author Alexander Klimenkov <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] |
|
16
|
|
|
final class VirtualProperty |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var string}null |
|
20
|
|
|
*/ |
|
21
|
36 |
|
public $exp = null; |
|
22
|
|
|
|
|
23
|
36 |
|
/** |
|
24
|
8 |
|
* @var string|null |
|
25
|
8 |
|
*/ |
|
26
|
|
|
public $name = null; |
|
27
|
|
|
|
|
28
|
36 |
|
/** |
|
29
|
9 |
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
public $options = []; |
|
32
|
9 |
|
|
|
33
|
|
|
public function __construct(array $data = [], ?string $name = null, ?string $exp = null, ?array $options = []) |
|
34
|
36 |
|
{ |
|
35
|
|
|
if (isset($data['value'])) { |
|
36
|
|
|
$data['name'] = $data['value']; |
|
37
|
|
|
unset($data['value']); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
foreach ($data as $key => $value) { |
|
41
|
|
|
if (!property_exists(self::class, $key)) { |
|
42
|
|
|
throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, self::class)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->{$key} = $value; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if (null !== $name) { |
|
49
|
|
|
$this->name = $name; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if (null !== $exp) { |
|
53
|
|
|
$this->exp = $exp; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (0 !== count($options)) { |
|
57
|
|
|
$this->options = $options; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
foreach ($options as $option) { |
|
61
|
|
|
if (is_array($option) && class_exists($option[0])) { |
|
62
|
|
|
$this->options[] = new $option[0]([], ...$option[1]); |
|
63
|
|
|
|
|
64
|
|
|
continue; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$this->options[] = $option; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/*public function __construct(array $data = [], string $name = '', ?string $exp = null, ?array $options = []) |
|
72
|
|
|
{ |
|
73
|
|
|
if (0 !== count($data)) { |
|
74
|
|
|
if (isset($data['value'])) { |
|
75
|
|
|
$data['name'] = $data['value']; |
|
76
|
|
|
unset($data['value']); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
foreach ($data as $key => $value) { |
|
80
|
|
|
if (!property_exists(self::class, $key)) { |
|
81
|
|
|
throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, self::class)); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$this->{$key} = $value; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return; |
|
88
|
|
|
} |
|
89
|
|
|
// echo 'z'.$name.'z'.PHP_EOL; |
|
90
|
|
|
$this->name = $name; |
|
91
|
|
|
$this->exp = $exp; |
|
92
|
|
|
$this->options = []; |
|
93
|
|
|
|
|
94
|
|
|
foreach ($options as $option) { |
|
95
|
|
|
if (is_array($option) && class_exists($option[0])) { |
|
96
|
|
|
$this->options[] = new $option[0](...$option[1]); |
|
97
|
|
|
|
|
98
|
|
|
continue; |
|
99
|
|
|
} |
|
100
|
|
|
$this->options[] = $option; |
|
101
|
|
|
} |
|
102
|
|
|
}*/ |
|
103
|
|
|
} |
|
104
|
|
|
|