| Total Complexity | 8 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 80% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class callback |
||
| 12 | { |
||
| 13 | private $validation; |
||
| 14 | |||
| 15 | 19 | public function __construct($validation) |
|
| 18 | 19 | } |
|
| 19 | |||
| 20 | 8 | public function validate($payload, ExecutionContextInterface $context) |
|
| 21 | { |
||
| 22 | 8 | foreach ($this->validation as $entry) { |
|
| 23 | 8 | if (!empty($entry['callback'])) { |
|
| 24 | 8 | $form = $context->getRoot(); |
|
| 25 | // hack to get error messages to show up at the correct place (also see below) |
||
| 26 | 8 | $context->setNode($form->getData(), $form, null, ''); |
|
| 27 | 8 | $result = call_user_func($entry['callback'], $this->to_array($form->getData())); |
|
| 28 | 8 | if (is_array($result)) { |
|
| 29 | foreach ($result as $field => $message) { |
||
| 30 | $context |
||
| 31 | ->buildViolation($message) |
||
| 32 | // There might be a nice way to do this, but I have no idea what it could be... |
||
| 33 | ->atPath('children[' . $field . '].data') |
||
| 34 | ->addViolation(); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | 8 | } |
|
| 40 | |||
| 41 | 8 | private function to_array(container $container) : array |
|
| 50 | } |
||
| 51 | } |
||
| 52 |