-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFilterValidator.php
More file actions
58 lines (46 loc) · 1.4 KB
/
FilterValidator.php
File metadata and controls
58 lines (46 loc) · 1.4 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Kitano\ConnectionBundle\Manager;
use Kitano\ConnectionBundle\Exception\InvalidFilterException;
use Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Type;
use Symfony\Component\Validator\Constraints\Collection;
class FilterValidator
{
protected $validator;
/**
* Validate and normalize input filters for connections retrieval
*
* @param array &$filters
* @throws InvalidFilterException
*/
public function validateFilters(array &$filters)
{
$filterConstraint = new Collection(array(
'type' => array(
new NotBlank(),
new NotNull(),
),
'depth' => new Type('integer'),
));
$filtersDefault = array(
'depth' => 1,
);
$filters = array_merge($filtersDefault, $filters);
$errorList = $this->getValidator()->validateValue($filters, $filterConstraint);
if (count($errorList) == 0) {
return true;
} else {
throw new InvalidFilterException($errorList);
}
}
public function setValidator(Validator\LegacyValidator $validator)
{
$this->validator = $validator;
}
public function getValidator()
{
return $this->validator;
}
}