|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bdf\Form\Leaf; |
|
4
|
|
|
|
|
5
|
|
|
use BadMethodCallException; |
|
6
|
|
|
use Bdf\Form\Button\ButtonInterface; |
|
7
|
|
|
use Bdf\Form\Child\ChildInterface; |
|
8
|
|
|
use Bdf\Form\Child\Http\HttpFieldPath; |
|
9
|
|
|
use Bdf\Form\ElementInterface; |
|
10
|
|
|
use Bdf\Form\Error\FormError; |
|
11
|
|
|
use Bdf\Form\RootElementInterface; |
|
12
|
|
|
use Bdf\Form\View\ElementViewInterface; |
|
13
|
|
|
use OutOfBoundsException; |
|
14
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessor; |
|
15
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
|
16
|
|
|
use Symfony\Component\Validator\Constraint; |
|
17
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
|
18
|
|
|
use Symfony\Component\Validator\ValidatorBuilder; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Wrap a leaf element for create a root element |
|
22
|
|
|
* Useful for create a singleton form |
|
23
|
|
|
*/ |
|
24
|
|
|
final class LeafRootElement implements RootElementInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var ElementInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $element; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* LeafRootElement constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param ElementInterface $element |
|
36
|
|
|
*/ |
|
37
|
212 |
|
public function __construct(ElementInterface $element) |
|
38
|
|
|
{ |
|
39
|
212 |
|
$this->element = $element; |
|
40
|
212 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function submit($data): ElementInterface |
|
46
|
|
|
{ |
|
47
|
1 |
|
$this->element->submit($data); |
|
48
|
|
|
|
|
49
|
1 |
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function patch($data): ElementInterface |
|
56
|
|
|
{ |
|
57
|
1 |
|
$this->element->patch($data); |
|
58
|
|
|
|
|
59
|
1 |
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function import($entity): ElementInterface |
|
66
|
|
|
{ |
|
67
|
1 |
|
$this->element->import($entity); |
|
68
|
|
|
|
|
69
|
1 |
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function value() |
|
76
|
|
|
{ |
|
77
|
1 |
|
return $this->element->value(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritdoc} |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function httpValue() |
|
84
|
|
|
{ |
|
85
|
1 |
|
return $this->element->httpValue(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* {@inheritdoc} |
|
90
|
|
|
*/ |
|
91
|
1 |
|
public function valid(): bool |
|
92
|
|
|
{ |
|
93
|
1 |
|
return $this->element->valid(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritdoc} |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function error(?HttpFieldPath $field = null): FormError |
|
100
|
|
|
{ |
|
101
|
1 |
|
return $this->element->error($field); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritdoc} |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function container(): ?ChildInterface |
|
108
|
|
|
{ |
|
109
|
1 |
|
return null; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritdoc} |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function setContainer(ChildInterface $container): ElementInterface |
|
116
|
|
|
{ |
|
117
|
1 |
|
throw new BadMethodCallException('Cannot set a container on a root element'); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritdoc} |
|
122
|
|
|
*/ |
|
123
|
1 |
|
public function root(): RootElementInterface |
|
124
|
|
|
{ |
|
125
|
1 |
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* {@inheritdoc} |
|
130
|
|
|
*/ |
|
131
|
|
|
public function view(?HttpFieldPath $field = null): ElementViewInterface |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->element->view($field); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* {@inheritdoc} |
|
138
|
|
|
*/ |
|
139
|
1 |
|
public function submitButton(): ?ButtonInterface |
|
140
|
|
|
{ |
|
141
|
1 |
|
return null; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* {@inheritdoc} |
|
146
|
|
|
*/ |
|
147
|
1 |
|
public function button(string $name): ButtonInterface |
|
148
|
|
|
{ |
|
149
|
1 |
|
throw new OutOfBoundsException('A leaf element do not have any buttons'); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* {@inheritdoc} |
|
154
|
|
|
*/ |
|
155
|
190 |
|
public function getValidator(): ValidatorInterface |
|
156
|
|
|
{ |
|
157
|
190 |
|
return (new ValidatorBuilder())->getValidator(); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* {@inheritdoc} |
|
162
|
|
|
*/ |
|
163
|
3 |
|
public function getPropertyAccessor(): PropertyAccessorInterface |
|
164
|
|
|
{ |
|
165
|
3 |
|
return new PropertyAccessor(); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* {@inheritdoc} |
|
170
|
|
|
*/ |
|
171
|
169 |
|
public function constraintGroups(): array |
|
172
|
|
|
{ |
|
173
|
169 |
|
return [Constraint::DEFAULT_GROUP]; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|