1 | <?php |
||
30 | class Field extends AbstractFormDefinitionComponent implements ActivationUsageInterface, DataPreProcessorInterface |
||
31 | { |
||
32 | /** |
||
33 | * @var string |
||
34 | * @validate NotEmpty |
||
35 | */ |
||
36 | private $name; |
||
37 | |||
38 | /** |
||
39 | * @var \Romm\Formz\Form\Definition\Field\Validation\Validator[] |
||
40 | */ |
||
41 | protected $validation = []; |
||
42 | |||
43 | /** |
||
44 | * @var \Romm\Formz\Form\Definition\Field\Behaviour\Behaviour[] |
||
45 | */ |
||
46 | protected $behaviours = []; |
||
47 | |||
48 | /** |
||
49 | * @var \Romm\Formz\Form\Definition\Condition\Activation |
||
50 | * @validate Romm.Formz:Internal\ConditionIsValid |
||
51 | */ |
||
52 | protected $activation; |
||
53 | |||
54 | /** |
||
55 | * @var \Romm\Formz\Form\Definition\Field\Settings\FieldSettings |
||
56 | */ |
||
57 | private $settings; |
||
58 | |||
59 | /** |
||
60 | * @param string $name |
||
61 | */ |
||
62 | public function __construct($name) |
||
63 | { |
||
64 | $this->name = $name; |
||
65 | |||
66 | $this->settings = GeneralUtility::makeInstance(FieldSettings::class); |
||
67 | $this->settings->attachParent($this); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getName() |
||
74 | { |
||
75 | return $this->name; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @return Validator[] |
||
80 | */ |
||
81 | public function getValidators() |
||
82 | { |
||
83 | return $this->validation; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param string $name |
||
88 | * @return bool |
||
89 | */ |
||
90 | public function hasValidator($name) |
||
91 | { |
||
92 | return true === isset($this->validation[$name]); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @param string $name |
||
97 | * @return Validator |
||
98 | * @throws EntryNotFoundException |
||
99 | */ |
||
100 | public function getValidator($name) |
||
101 | { |
||
102 | if (false === $this->hasValidator($name)) { |
||
103 | throw EntryNotFoundException::validatorNotFound($name); |
||
104 | } |
||
105 | |||
106 | return $this->validation[$name]; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @param string $name |
||
111 | * @param string $className |
||
112 | * @return Validator |
||
113 | * @throws DuplicateEntryException |
||
114 | */ |
||
115 | public function addValidator($name, $className) |
||
131 | |||
132 | /** |
||
133 | * @return Behaviour[] |
||
134 | */ |
||
135 | public function getBehaviours() |
||
139 | |||
140 | /** |
||
141 | * @param string $name |
||
142 | * @return bool |
||
143 | */ |
||
144 | public function hasBehaviour($name) |
||
148 | |||
149 | /** |
||
150 | * @param string $name |
||
151 | * @return Behaviour |
||
152 | * @throws EntryNotFoundException |
||
153 | */ |
||
154 | public function getBehaviour($name) |
||
162 | |||
163 | /** |
||
164 | * @param string $name |
||
165 | * @param string $className |
||
166 | * @return Behaviour |
||
167 | * @throws DuplicateEntryException |
||
168 | */ |
||
169 | public function addBehaviour($name, $className) |
||
185 | |||
186 | /** |
||
187 | * @return ActivationInterface |
||
188 | * @throws SilentException |
||
189 | */ |
||
190 | public function getActivation() |
||
198 | |||
199 | /** |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function hasActivation() |
||
206 | |||
207 | /** |
||
208 | * @return ActivationInterface |
||
209 | */ |
||
210 | public function addActivation() |
||
221 | |||
222 | /** |
||
223 | * @return FieldSettings |
||
224 | */ |
||
225 | public function getSettings() |
||
229 | |||
230 | /** |
||
231 | * @param DataPreProcessor $processor |
||
232 | */ |
||
233 | public static function dataPreProcessor(DataPreProcessor $processor) |
||
251 | } |
||
252 |