1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TheCodingMachine\FluidSchema; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use function addslashes; |
8
|
|
|
use Doctrine\DBAL\Types\Type; |
9
|
|
|
use function var_export; |
10
|
|
|
|
11
|
|
|
class TdbmFluidColumnJsonOptions |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var TdbmFluidColumnOptions |
15
|
|
|
*/ |
16
|
|
|
private $tdbmFluidColumnOptions; |
17
|
|
|
|
18
|
|
|
public function __construct(TdbmFluidColumnOptions $tdbmFluidColumnOptions) |
19
|
|
|
{ |
20
|
|
|
$this->tdbmFluidColumnOptions = $tdbmFluidColumnOptions; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function key(string $name): self |
24
|
|
|
{ |
25
|
|
|
$this->addAnnotation('JsonKey', ['key' => $name]); |
26
|
|
|
return $this; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function datetimeFormat(string $format): self |
30
|
|
|
{ |
31
|
|
|
$this->addAnnotation('JsonFormat', ['date' => $format]); |
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param int|null $decimals The number of decimals |
37
|
|
|
* @param string|null $point The decimal point |
38
|
|
|
* @param string|null $separator The thousands separator |
39
|
|
|
* @param string|null $unit The suffix to append after a number |
40
|
|
|
*/ |
41
|
|
|
public function numericFormat(?int $decimals = null, ?string $point = null, ?string $separator = null, ?string $unit = null): self |
42
|
|
|
{ |
43
|
|
|
$params = []; |
44
|
|
|
if ($decimals !== null) { |
45
|
|
|
$params['decimals'] = $decimals; |
46
|
|
|
} |
47
|
|
|
if ($point !== null) { |
48
|
|
|
$params['point'] = $point; |
49
|
|
|
} |
50
|
|
|
if ($separator !== null) { |
51
|
|
|
$params['separator'] = $separator; |
52
|
|
|
} |
53
|
|
|
if ($unit !== null) { |
54
|
|
|
$params['unit'] = $unit; |
55
|
|
|
} |
56
|
|
|
$this->addAnnotation('JsonFormat', $params); |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Serialize in JSON by getting the property from an object. |
62
|
|
|
*/ |
63
|
|
|
public function formatUsingProperty(string $property): self |
64
|
|
|
{ |
65
|
|
|
$this->addAnnotation('JsonFormat', ['property' => $property]); |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Serialize in JSON by calling a method from an object. |
71
|
|
|
*/ |
72
|
|
|
public function formatUsingMethod(string $method): self |
73
|
|
|
{ |
74
|
|
|
$this->addAnnotation('JsonFormat', ['method' => $method]); |
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function ignore(): self |
79
|
|
|
{ |
80
|
|
|
$this->addAnnotation('JsonIgnore'); |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function include(): self |
85
|
|
|
{ |
86
|
|
|
$this->addAnnotation('JsonInclude'); |
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function recursive(): self |
91
|
|
|
{ |
92
|
|
|
$this->addAnnotation('JsonRecursive'); |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function collection(string $key): self |
97
|
|
|
{ |
98
|
|
|
$this->addAnnotation('JsonCollection', ['key' => $key]); |
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $annotation |
104
|
|
|
* @param mixed $content |
105
|
|
|
* @param bool $replaceExisting |
106
|
|
|
* @return TdbmFluidColumnGraphqlOptions |
107
|
|
|
*/ |
108
|
|
|
public function addAnnotation(string $annotation, $content = null, bool $replaceExisting = true, bool $explicitNull = false): self |
109
|
|
|
{ |
110
|
|
|
$this->tdbmFluidColumnOptions->addAnnotation($annotation, $content, $replaceExisting, $explicitNull); |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function endJsonSerialize(): TdbmFluidColumnOptions |
115
|
|
|
{ |
116
|
|
|
return $this->tdbmFluidColumnOptions; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function then(): TdbmFluidTable |
120
|
|
|
{ |
121
|
|
|
return $this->tdbmFluidColumnOptions->then(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function column(string $name): TdbmFluidColumn |
125
|
|
|
{ |
126
|
|
|
return $this->tdbmFluidColumnOptions->column($name); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|