summaryrefslogtreecommitdiff
path: root/src/Controllers/ValidationController.php
blob: 6d42a7e8e260c4e6027b2fc9544442921921a598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

namespace FlatFileForms\Controllers;

use FlatFileForms\Builder;
use FlatFileForms\Utilities;
use FlatFileForms\Validator;

class ValidationController
{
  public function validateRequest(Builder $builder, Validator $validator): array
  {
    /**@var Utilities $utilities*/
    global $utilities;

    $fields = $builder->buildFields($_GET['page'] ?? null);

    $result = $validator->validateRequest($fields);

    $content['data'] = $result['fields'];
    if (! empty($result['error'])) {
      $content['error'] = $result['error'];
    }

    return $content;
  }
}